iOS Text-to-Speech playback
Last Update:2015-07-31
Source: Internet
Author: User
<span id="Label3"></p><span style="font-family:SimSun; font-size:12px"><span style="font-family:SimSun; font-size:12px"> <span style="background-color:rgb(255,255,255)">to implement TTS primarily relies on avspeechsynthesizer,avspeechutterance,avspeechsynthesisvoice, to use these classes must first join the</span> <span style="background-color:rgb(255,255,255)"> Avfoundation frame:</span> <span style="background-color:rgb(255,255,255)"></span> </span></span><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><span style="font-family:SimSun; font-size:12px"><span style="background-color:rgb(255,255,255)">Avspeechsynthesisvoice: used to configure pronunciation, supported pronunciation is very much.</span></span></p></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><span style="font-family:SimSun; font-size:12px"><span style="background-color:rgb(255,255,255)"><br></span></span></p></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><span style="font-family:SimSun; font-size:12px"><span style="background-color:rgb(255,255,255)">The types of languages held include:<br>"[avspeechsynthesisvoice 0x978a0b0]language:th-th",<br>"[avspeechsynthesisvoice 0x977a450]language:pt-br",<br>"[avspeechsynthesisvoice 0x977a480]language:sk-sk",<br>"[avspeechsynthesisvoice 0x978ad50]language:fr-ca",<br>"[avspeechsynthesisvoice 0x978ada0]language:ro-ro",<br>"[avspeechsynthesisvoice 0x97823f0]language:no-no",<br>"[avspeechsynthesisvoice 0x978e7b0]language:fi-fi",<br>"[avspeechsynthesisvoice 0x978af50]language:pl-pl",<br>"[avspeechsynthesisvoice 0x978afa0]language:de-de",<br>"[avspeechsynthesisvoice 0x978e390]language:nl-nl",<br>"[avspeechsynthesisvoice 0x978b030]language:id-id",<br>"[avspeechsynthesisvoice 0x978b080]language:tr-tr",<br>"[avspeechsynthesisvoice 0x978b0d0]language:it-it",<br>"[avspeechsynthesisvoice 0x978b120]language:pt-pt",<br>"[avspeechsynthesisvoice 0x978b170]language:fr-fr",<br>"[avspeechsynthesisvoice 0x978b1c0]language:ru-ru",<br>"[avspeechsynthesisvoice 0x978b210]language:es-mx",<br>"[avspeechsynthesisvoice 0x978b2d0]language:zh-hk",<br>"[avspeechsynthesisvoice 0x978b320]language:sv-se",<br>"[avspeechsynthesisvoice 0x978b010]language:hu-hu",<br>"[avspeechsynthesisvoice 0x978b440]language:zh-tw",<br>"[avspeechsynthesisvoice 0x978b490]language:es-es",<br>"[avspeechsynthesisvoice 0x978b4e0]language:zh-cn",<br>"[avspeechsynthesisvoice 0x978b530]language:nl-be",<br>"[avspeechsynthesisvoice 0x978b580]language:en-gb",<br>"[avspeechsynthesisvoice 0x978b5d0]language:ar-sa",<br>"[avspeechsynthesisvoice 0x978b620]language:ko-kr",<br>"[avspeechsynthesisvoice 0x978b670]language:cs-cz",<br>"[avspeechsynthesisvoice 0x978b6c0]language:en-za",<br>"[avspeechsynthesisvoice 0x978aed0]language:en-au",<br>"[avspeechsynthesisvoice 0x978af20]language:da-dk",<br>"[avspeechsynthesisvoice 0x978b810]language:en-us",<br>"[avspeechsynthesisvoice 0x978b860]language:en-ie",<br>"[avspeechsynthesisvoice 0x978b8b0]language:hi-in",<br>"[avspeechsynthesisvoice 0x978b900]language:el-gr",<br><br></span></span></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><span style="font-family:SimSun; font-size:12px"><span style="background-color:rgb(255,255,255)">[avspeechsynthesis voicespeechvoices] class method can be used to see the type of pronunciation supported;</span></span></p></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><span style="font-family:SimSun; font-size:12px"><span style="background-color:rgb(255,255,255)">avspeechutterance: This class is used to synthesize strings into speech objects that are provided to Avspeechsynthesizer for playback, and this class has some</span></span> instance methods to control the speed, pitch, and so On.</p></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px">Added a TextView on storyboard to play the text message on the TextView while tapping the Screen.</p></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"></p></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px">Implementation Code:</p></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"></p></p><pre name="code" class="objc"><pre name="code" class="objc"><span style= "font-size:14px;" > #import "ViewController.h" #import <AVFoundation/AVFoundation.h> @interface viewcontroller () @property ( weak, nonatomic) iboutlet uitextview *textviewoutlet; @end @implementation viewcontroller-(void) viewdidload {[super viewdidload];} -(void) touchesbegan: (nsset *) touches withevent: (uievent *) event {avspeechsynthesizer *speechsynthesizer = [[ Avspeechsynthesizer alloc] init]; Avspeechsynthesisvoice *voice = [avspeechsynthesisvoice voicewithlanguage:@ "zh-tw"]; Avspeechutterance *utterance = [avspeechutterance Speechutterancewithstring:_textviewoutlet.text];utterance.voice = Voice;utterance.rate = avspeechutteranceminimumspeechrate; [speechsynthesizer speakutterance:utterance];} @end </span></pre></pre><br>---end<br><p><p></p></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><br></p></p><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><p style="margin-top:0px; margin-bottom:5px; padding-top:0px; padding-bottom:0px; border:0px none; list-style:outside none none; word-wrap:normal; word-break:normal; line-height:21px; font-size:14px"><br></p></p><span style="font-family:SimSun; font-size:12px"><span style="font-family:SimSun; font-size:12px"><span style="background-color:rgb(255,255,255)"></span></span></span> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article is the original blogger article, reproduced please indicate the source: http://blog.csdn.net/zhangwenhai001</p></p> <p><p>iOS Text-to-Speech playback</p></p></span>