IOS development diary 50-text-to-speech (TTS), 50-TTS

Source: Internet
Author: User

IOS development diary 50-text-to-speech (TTS), 50-TTS

Today, the blogger has a text-to-speech (TTS) Demand and encountered some difficulties. I would like to share with you the hope to make common progress.

Text-To-Speech technology, also known as TTS, is short for Text To Speech. This technology is used when iOS wants To implement functions such as voicebooks.

This function is available only after iOS7. You need to import the AVFoundation Library

 

// After the iPhone mute mode is enabled, the sound cannot be played. You need to enable background playback.

AVAudioSession * audioSession = [AVAudioSession sharedInstance];

[AudioSession setCategory: AVAudioSessionCategoryPlayback error: nil];

// Speech synthesizer, which is the main interface

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

// A paragraph to be said, the playback content interface of the Speech Synthesizer

AVSpeechUtterance * utterance1 = [[AVSpeechUtterance alloc] initWithString: [NSString stringWithFormat: @ "% @", @ "real-time"]; // text to be converted

// The pause time after reading a paragraph

Utterance1.postUtteranceDelay = 0.1;

// Speech Rate

Utterance1.rate = 0.4;

// Start playing the content

[Av speakUtterance: utterance1];

 

AVSpeechSynthesisVoice defines a series of sounds, mainly in different languages and regions. Below are some of his attributes and methods.

VoiceWithLanguage: gets a sound based on the language.
SpeechVoices: Voice supported by the current device
CurrentLanguageCode: gets the language string of the current sound, such as "ZH-cn"
Language: Obtain the current language.

 

The above is a simple TTS playback. If you want to perform more complex operations, you can follow the AVSpeechSynthesizerDelegate Protocol to implement the method.

Synthesizer delegation provides Response interfaces for some events.

DidCancelSpeechUtterance: the message has been canceled.
DidContinueSpeechUtterance: continue talking
DidFinishSpeechUtterance: Completed
DidPauseSpeechUtterance: paused
DidStartSpeechUtterance: started
WillSpeakRangeOfSpeechString: to say something

Related Article

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.