dobiho
dobiho

Reputation: 1035

How to change speech rate during speaking using AVSpeechSynthesizer in iOS 7

I'd like to change speech rate during speaking text to know how fast.

I tested as below 2 ways , but speech rate does not changed.

- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpeechString:NSRange)characterRange utterance:(AVSpeechUtterance *)utterance{

    // 1. AVSpeechUtterance *SpeechUtterence; 
    SpeechUtterence.rate = fSpeechSpeed;

   // 2. set fSpeechSpeed from other view 
    utterance.rate = fSpeechSpeed;

}

Upvotes: 1

Views: 1488

Answers (1)

Brett DiDonato
Brett DiDonato

Reputation: 1952

If the speech synthesizer is already speaking that means you already called the speakUtterance method. At that point changing any of the AVSpeechUtterance instance properties such as rate will not have any effect. If you want to change the rate of the currently speaking utterance you need to use the method you listed above (willSpeakRangeOfSpeechString) to pinpoint your location in the string assigned to the utterance, call the speech synthesizer method stopSpeakingAtBoundary to stop the current utterance, create a new utterance based off of the remaining string and then call speakUtterance again.

Upvotes: 5

Related Questions