0

J'utilise le code ci-dessous pour parler une chaîne dans mon application.Swift Effacer AVSpeechSynthesizer avant de parler

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) 

Si la chaîne est alors modifiée et a demandé de lire à nouveau, il répète la chaîne précédente à la fin de la nouvelle.

Est-il possible d'effacer AVSpeechSynthesizer avant de commencer?

Merci

Répondre

0

Je dois que cela fonctionne dans une aire de jeux. Rien n'est répété.

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