Implementation of iOS Self-TTS technology: Voice broadcast

Source: Internet
Author: User

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

One, there are several points to note when using iOS to bring TTS:

    1. This function is only after iOS7
    2. Need Avfoundation Library
    3. Avspeechsynthesizer: Speech synthesizer, can be imagined as a person can speak, is the most important interface
    4. Avspeechsynthesisvoice: Can imagine an adult's voice
    5. Avspeechutterance: Can be imagined as a word to say

Two, code example, play voice

    //Voice BroadcastAvspeechutterance *utterance = [avspeechutterance speechutterancewithstring:@"The moonlight before the bed, is suspected to be ground frost. "]; Utterance.pitchmultiplier=0.8; //Chinese pronunciationAvspeechsynthesisvoice *voice = [Avspeechsynthesisvoice voicewithlanguage:@"ZH-CN"]; //English pronunciation//avspeechsynthesisvoice *voice = [Avspeechsynthesisvoice voicewithlanguage:@ "EN-GB"];Utterance.voice=Voice; NSLog (@"%@", [Avspeechsynthesisvoice speechvoices]); Avspeechsynthesizer*synth =[[Avspeechsynthesizer alloc]init]; [Synth speakutterance:utterance];

Three, Avspeechsynthesizer introduction

This class is like a talking person, can "speak", can "pause" to speak, can "continue" to speak, you can determine whether he is currently speaking. The following methods or properties are available:

    • Talk: Speakutterance
    • Control: Continuespeaking (continued), Pausespeakingatboundary (Pause speaking), paused (properties of the paused state), speaking (speaking state), Stopspeakingatboundary ( Stop talking)
    • Commissioned by: Delegate

Four, Avspeechboundary Introduction

This is an enumeration. In the pause, or stop talking, the way to stop is marked with this enumeration. Two types are included:

    • Avspeechboundaryimmediate: Stop Now
    • Avspeechboundaryword: Say an entire word and stop.

Five, Avspeechsynthesizerdelegate Introduction

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

Six, Avspeechsynthesisvoice Introduction

Avspeechsynthesisvoice defines a range of sounds, mainly in different languages and regions.

    • 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

Seven, Avspeechutterance Introduction

This class is the one thing to say. The main properties and methods are:

    • Pitchmultiplier: Pitch
    • Postutterancedelay: Pause time after reading a paragraph
    • Preutterancedelay: Pause before reading a passage
    • Rate: Reading speed, the system offers three speeds: avspeechutteranceminimumspeechrate, avspeechutterancemaximumspeechrate, Avspeechutterancedefaultspeechrate
    • Speechstring: the string to read
    • Voice: The sound used is the Avspeechsynthesisvoice object
    • Volume: Volume

Eight, UML diagram

The relationships of these classes are as follows:

Implementation of iOS Self-TTS technology: Voice broadcast

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.