iOS speech synthesis

Add Reference

1
import AVFoundation

Play voice

1
2
3
4
5
6
7
8
9

the let Player = AVSpeechSynthesizer ();
player.delegate = Self ;
the let U = AVSpeechUtterance (String: "The weather today is good" );
u.voice = AVSpeechSynthesisVoice (Language: "zh-CN" );
u.volume = 1.0 ; // volume [0-1]. 1 the Default =
u.rate = 0.48 ; // playing speed
u.pitchMultiplier = 1.0 ; // play reference tone [0.5 - 2] = the Default. 1
player.speakUtterance (U);

In iPhone6the following rateset 0.1or will soon iOS will read the pit ah

Proxy method

. 1 
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
large column   iOS speech synthesizer > 13 is
14
15
// start playing 
FUNC (Synthesizer: AVSpeechSynthesizer, Utterance, didStartSpeechUtterance: AVSpeechUtterance) { Print ( "start playing" ) }



// playback
FUNC (Synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString CharacterRange: NSRange, Utterance,: AVSpeechUtterance) { the let Process = Double (characterRange.location) / Double (utterance.speechString.characters. COUNT ); Print ( "playback, the playback progress of : (Process) " ) }




// finished playing
FUNC (Synthesizer: AVSpeechSynthesizer, Utterance, didFinishSpeechUtterance: AVSpeechUtterance) { Print ( "finished playing" ) }


Common method

1
2
3
4
// stop playing
player.stopSpeakingAtBoundary ( AVSpeechBoundary . Immediate );
// pause playback
player.pauseSpeakingAtBoundary ( AVSpeechBoundary . Immediate );

Guess you like

Origin www.cnblogs.com/wangziqiang123/p/11711084.html