0

Ich benutze den folgenden Code, um eine Zeichenfolge in meiner App zu sprechen.Swift Clear AVSpeechSynthesizer Vor dem Sprechen

var mySynthesizer = AVSpeechSynthesizer() 
var myUtterance = AVSpeechUtterance(string: "Hello World!") 
myUtterance.voice = AVSpeechSynthesisVoice(language: "en-US") 
myUtterance.pitchMultiplier = 1.15 
myUtterance.rate = 0.5 
mySynthesizer.speak(utterance) 

Wenn die Zeichenfolge dann geändert wird, und fragte noch einmal zu lesen, wiederholen sie die vorherige Zeichenfolge am Ende des neuen.

Ist es möglich, AVSpeechSynthesizer vor Beginn zu löschen?

Danke

Antwort

0

Ich habe dies auf einem Spielplatz zu arbeiten. Nichts wird wiederholt.

//: Playground - noun: a place where people can play 

import UIKit 
import AVFoundation 
import PlaygroundSupport 

// this is needed otherwise the playground program exits before the speech is synthesized. 
PlaygroundPage.current.needsIndefiniteExecution = true 


var mySynthesizer = AVSpeechSynthesizer() 
var helloUtterance = AVSpeechUtterance(string: "Hello World!") 
helloUtterance.voice = AVSpeechSynthesisVoice(language: "en-US") 
helloUtterance.pitchMultiplier = 1.25 
helloUtterance.rate = 0.5 
mySynthesizer.speak(helloUtterance) 

let responseUtterance = AVSpeechUtterance(string: "Hey human. It's me, the world") 
responseUtterance.pitchMultiplier = 0.75 
responseUtterance.rate = 0.45 
mySynthesizer.speak(responseUtterance) 
Verwandte Themen