iOS Development journal 50-text-to-speech (TTS)

Source: Internet
Author: User

Today bloggers have a text-to-speech (TTS) needs, encountered some difficulties, here and we share, hope to progress together.

Text-to-speech technology, also called TTS, is the abbreviation for text to speech. iOS uses this technology when it wants to do features like audio books.

This feature is only iOS7 after you import the Avfoundation library

When the iphone mute mode is turned on, the sound will not play and you need to turn on background playback

Avaudiosession *audiosession = [Avaudiosession sharedinstance];

[Audiosession Setcategory:avaudiosessioncategoryplayback Error:nil];

Speech synthesizer, is the most important interface

Avspeechsynthesizer *av = [[Avspeechsynthesizer alloc]init];

To say a word, the speech synthesizer's playback content interface

Avspeechutterance *utterance1 = [[Avspeechutterance alloc]initwithstring:[nsstring stringWithFormat:@ "%@", @ "real time"]]; Text that needs to be converted

Pause time after reading a paragraph

utterance1.postutterancedelay=0.1;

Rate of speech

utterance1.rate=0.4;

Start playing content

[AV Speakutterance:utterance1];

Avspeechsynthesisvoice defines a range of sounds, mainly in different languages and regions. Here are a few of his properties and methods

Voicewithlanguage: Get a voice based on the language you've developed.
Speechvoices: Get the sound supported by the current device
Currentlanguagecode: Gets the language string of the current sound, such as "ZH-CN"
Language: Getting the current language

The above is a simple TTS playback, if you want to do more complex operations, you can follow the Avspeechsynthesizerdelegate protocol, implement its methods

The delegate for the synthesizer, for some events, provides the interface for the response.

Didcancelspeechutterance: I've canceled my speech.
Didcontinuespeechutterance: has continued to speak
Didfinishspeechutterance: Already finished.
Didpausespeechutterance: Already paused
Didstartspeechutterance: Already started
Willspeakrangeofspeechstring: Going to say a word

iOS Development journal 50-text-to-speech (TTS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.