0

私のアプリで文字列を話すために、以下のコードを使用しています。Swift Clear AVSpeechSynthesizerを話す前に

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) 

文字列が、その後変更して再度読み込むように頼まれた場合、それは新しいものの最後に、前の文字列を繰り返します。

開始する前にAVSpeechSynthesizerをクリアすることはできますか?

ありがとうございました

答えて

0

私はこれを遊び場で動作させました。何も繰り返されません。

//: 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)