AVSpeechSynthesizer language synthesizer,

Source: Internet
Author: User

AVSpeechSynthesizer language synthesizer,

The speech synthesizer technology is launched by iOS7, which can implement the non-network speech function and support multiple languages.

1. import <AVFoundation/AVFoundation. h>

Define a member variable AVSpeechSynthesizer * _ synthesizer for language synthesis;

Define a member variable AVSpeechSynthesisVoice * _ voice, instantiate the language of speech (Chinese and English)

    

2. instantiate the language and initialize the language synthesizer.

// If the text content is Chinese, useZh_CN; if the text content is English, use en-US;

    _voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; //Zh_CN ChineseEn-US English

// To recite the speech, a speech synthesizer is required to initialize the language synthesizer.

      _synthesizer = [[AVSpeechSynthesizer alloc] init];

3. instantiate the voice object AVSpeechUtterance and specify the content to be read.

// Instantiate the AVSpeechUtterance object and specify the read content

    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:_textView.text];

4. Specify the language and recitation speed

// Specify the language

Utterance. voice = _ voice;

// Speech speed

Utterance. rate = 0.3; // 0.1 Chinese characters. The English version is 0.3. The actual version prevails.

5. Start

          [_synthesizer speakUtterance:utterance];

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.