iOS Development--voice broadcast

Source: Internet
Author: User

Nothing to do, suddenly want to listen to the apple voice function, and then on their own information to do.

Before iOS7, you might need a third-party repository to implement voice-broadcast text content. Now on the IOS7, the system provides us with the function of voice broadcast text, we can not only broadcast English content, can also broadcast Chinese characters, so for developers is really a boon.

You need to import Avfoundattion:

Current device judgment

NSString *warnmsg = @ "The weather is really good today, work refueling";

if ([[[[Uidevice Currentdevice] Systemversion]integervalue]>=7.0) {

Avspeechutterance

Avspeechutterance is the set of text content that needs to be broadcast-warnmsg, speech rate-rate, and language type-preferredlang, and Avspeechsynthesizer is the class that starts to play synchronously.

Avspeechutterance *utterance =[avspeechutterance speechutterancewithstring:warnmsg];

Rate

Utterance.rate *= 0.8;

Sync Voice

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

/**

* Get current system voice

*/

NSString *preferredlang = @ "";

setting of the language

Preferredlang = @ "ZH-HK";

Avspeechsynthesisvoice *voice =[avspeechsynthesisvoice voicewithlanguage:[nsstring stringWithFormat:@ "%@", Preferredlang]];

Utterance.voice = Voice;

[Synth speakutterance:utterance];

}

iOS Development--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.