How to use IOS 7 for Avspeechsynthesizer National audiobooks (4)

Source: Internet
Author: User
<span id="Label3"></p><p><p><strong>Control: we must learn to control</strong></p></p><p><p>Master Yoda (movie star Wars) has words: the key is Control. This storybook is a word read out in a word, and I am willing to add two buttons, tones and speed to it so that we can adjust speech synthesis in real time.</p></p><p><p>Or rwtpageviewcontroller.m, declare the following properties after the Nextspeechindex property:</p></p> <table border="0" cellpadding="0"> <tbody> <tr> <td><p><span style="color:#A61390;">@property</span> <span style="color:#002200;">(</span>nonatomic, assign<span style="color:#002200;">)</span> <span style="color:#A61390;">float</span> currentpitchmultiplier;</p><p><span style="color:#A61390;">@property</span> <span style="color:#002200;">(</span>nonatomic, assign<span style="color:#002200;">)</span> <span style="color:#A61390;">float</span> currentrate;</p></td> </tr> </tbody> </table><p><p>After the Gotopreviouspage: method is added such as the following methods:</p></p> <table border="0" cellpadding="0"> <tbody> <tr> <td><p><p><span style="color:#002200;">-</span> <span style="color:#002200;">(</span><span style="color:#A61390;">void</span><span style="color:#002200;">)</span>lowerpitch <span style="color:#002200;">{</span></p></p> <p><p><span style="color:#A61390;">if</span> <span style="color:#002200;">(</span>self.currentpitchmultiplier > 0.5f<span style="color:#002200;">)</span> <span style="color:#002200;">{</span></p></p> <p><p>Self.currentpitchmultiplier <span style="color:#002200;">=</span> MAX<span style="color:#002200;">(</span>self.currentpitchmultiplier <span style="color:#002200;">*</span> 0.8f, 0.5f<span style="color:#002200;">) </span>;</p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">-</span> <span style="color:#002200;">(</span><span style="color:#A61390;">void</span><span style="color:#002200;">)</span>raisepitch <span style="color:#002200;">{</span></p></p> <p><p><span style="color:#A61390;">if</span> <span style="color:#002200;">(</span>self.currentpitchmultiplier < 2.0f<span style="color:#002200;">)</span> <span style="color:#002200;">{</span></p></p> <p><p>Self.currentpitchmultiplier <span style="color:#002200;">=</span> MIN<span style="color:#002200;">(</span>self.currentpitchmultiplier <span style="color:#002200;">*</span> 1.2f, 2.0f<span style="color:#002200;">) </span>;</p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">-</span> <span style="color:#002200;">(</span><span style="color:#A61390;">void</span><span style="color:#002200;">)</span>lowerrate <span style="color:#002200;">{</span></p></p> <p><p><span style="color:#A61390;">if</span> <span style="color:#002200;">(</span>self.currentrate > Avspeechutteranceminimumspeechrate<span style="color:#002200;">)</span> <span style="color:#002200;">{</span></p></p> <p><p>Self.currentrate <span style="color:#002200;">=</span> MAX<span style="color:#002200;">(</span>self.currentrate <span style="color:#002200;">*</span> 0.8f, avspeechutteranceminimumspeechrate <span style="color:#002200;">)</span>;</p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">-</span> <span style="color:#002200;">(</span><span style="color:#A61390;">void</span><span style="color:#002200;">)</span>raiserate <span style="color:#002200;">{</span></p></p> <p><p><span style="color:#A61390;">if</span> <span style="color:#002200;">(</span>self.currentrate < avspeechutterancemaximumspeechrate<span style="color:#002200;">)</span> <span style="color:#002200;">{</span></p></p> <p><p>Self.currentrate <span style="color:#002200;">=</span> MIN<span style="color:#002200;">(</span>self.currentrate <span style="color:#002200;">*</span> 1.2f, avspeechutterancemaximumspeechrate <span style="color:#002200;">)</span>;</p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">-(</span><span style="color:#A61390;">void</span><span style="color:#002200;">)</span> speakagain <span style="color:#002200;">{</span></p></p> <p><p><span style="color:#A61390;">if</span> <span style="color:#002200;">(</span>self.nextspeechindex <span style="color:#002200;">= =</span> <span style="color:#002200;">[[</span>self currentpage<span style="color:#002200;">]</span>. Utterances Count<span style="color:#002200;">])</span> <span style="color:#002200;">{</span></p></p> <p><p>Self.nextspeechindex <span style="color:#002200;">=</span> <span style="color:#2400D9;">0</span>;</p></p> <p><p><span style="color:#002200;">[</span>self speaknextutterance<span style="color:#002200;">]</span>;</p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">}</span></p></p></td> </tr> </tbody> </table><p><p>These methods are connected to the button on The voice control panel.</p></p><p><p></p></p> <ul type="disc"> <ul type="disc"> <li>Lowerpitch: and Raisepitch: methods are used to reduce and improve Pitch. Each time it will be reduced or added 20% on the basis of the Original. however, This value is limited to (0.5-2.0).</li> <li>Lowerrate: and the Raiserate method is used to reduce and increase the spoken speech speed, each time on the original basis of +/-20%, the overall range is limited to avspeechutteranceminimumspeechrate and Between the Avspeechutterancemaximumspeechrate.<p></p><p></p></li> <li>Speakagain: resets the index value of the current statement and displays the corresponding text content Again.</li> </ul> </ul><p><p>Create a button, and then add the following methods after the Raiserate method:</p></p> <table border="0" cellpadding="0"> <tbody> <tr> <td><p><p><span style="color:#002200;">-(</span><span style="color:#A61390;">void</span><span style="color:#002200;">)</span> addspeechcontrolwithframe<span style="color:#002200;">:</span> <span style="color:#002200;">(</span>cgrect<span style="color:#002200;">)</span> frame title <span style="color:#002200;"> :(</span><span style="color:#400080;">nsstring</span> <span style="color:#002200;">*)</span> title Action<span style="color:#002200;">:(</span><span style="color:#A61390;">SEL</span><span style="color:#002200;">)</span> selector <span style="color:#002200;">{</span></p></p> <p><p>UIButton <span style="color:#002200;">*</span>Controlbutton <span style="color:#002200;">=</span> <span style="color:#002200;">[</span>UIButton buttonwithtype<span style="color:#002200;">:</span> Uibuttontyperoundedrect<span style="color:#002200;">]</span>;</p></p> <p><p>Controlbutton.frame <span style="color:#002200;">=</span> frame;</p></p> <p><p>Controlbutton.backgroundcolor <span style="color:#002200;">=</span> <span style="color:#002200;">[</span>uicolor colorwithwhite<span style="color:#002200;">:</span>0.9f Alpha<span style="color:#002200;">:</span>1.0f<span style="color:#002200;">] </span>;</p></p> <p><p><span style="color:#002200;">[</span>Controlbutton settitle<span style="color:#002200;">:</span>title forstate<span style="color:#002200;">:</span>uicontrolstatenormal<span style="color:#002200;">]</span>;</p></p> <p><p><span style="color:#002200;">[</span>Controlbutton addTarget<span style="color:#002200;">:</span>Self</p></p> <p><p>Action<span style="color:#002200;">:</span>selector forcontrolevents<span style="color:#002200;">:</span>uicontroleventtouchupinside<span style="color:#002200;">]</span>;</p></p> <p><p><span style="color:#002200;">[</span>self.view addsubview<span style="color:#002200;">:</span>Controlbutton<span style="color:#002200;">]</span>;</p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">-</span> <span style="color:#002200;">(</span><span style="color:#A61390;">void</span><span style="color:#002200;">)</span>addspeechcontrols <span style="color:#002200;">{</span></p></p> <p><p><span style="color:#002200;">[</span>self addspeechcontrolwithframe<span style="color:#002200;">:</span>cgrectmake<span style="color:#002200;">(</span><span style="color:#2400D9;"></span> <span style="color:#2400D9;">485</span>, <span style="color:#2400D9;">150 </span>, <span style="color:#2400D9;"></span><span style="color:#002200;">)</span></p></p> <p><p>Title<span style="color:#002200;">:</span><em><span style="color:#11740A;">@</span></em><span style="color:#BF1D1A;">"Lower Pitch"</span></p></p> <p><p>Action<span style="color:#002200;">:</span><span style="color:#A61390;">@selector</span><span style="color:#002200;">(</span>lowerpitch<span style="color:#002200;">)]</span>;</p></p> <p><p><span style="color:#002200;">[</span>self addspeechcontrolwithframe<span style="color:#002200;">:</span>cgrectmake<span style="color:#002200;">(</span><span style="color:#2400D9;">222</span>, <span style="color:#2400D9;">485</span>, <span style="color:#2400D9;"></span> <span style="color:#2400D9;"></span> - <span style="color:#002200;">)</span></p></p> <p><p>Title<span style="color:#002200;">:</span><em><span style="color:#11740A;">@</span></em><span style="color:#BF1D1A;">"Raise Pitch"</span></p></p> <p><p>Action<span style="color:#002200;">:</span><span style="color:#A61390;">@selector</span><span style="color:#002200;">(</span>raisepitch<span style="color:#002200;">)]</span>;</p></p> <p><p><span style="color:#002200;">[</span>self addspeechcontrolwithframe<span style="color:#002200;">:</span>cgrectmake<span style="color:#002200;">(</span><span style="color:#2400D9;">422</span>, <span style="color:#2400D9;">485</span>, <span style="color:#2400D9;"></span> <span style="color:#2400D9;"></span> - <span style="color:#002200;">)</span></p></p> <p><p>Title<span style="color:#002200;">:</span><em><span style="color:#11740A;">@</span></em><span style="color:#BF1D1A;">"Lower rate"</span></p></p> <p><p>Action<span style="color:#002200;">:</span><span style="color:#A61390;">@selector</span><span style="color:#002200;">(</span>lowerrate<span style="color:#002200;">)]</span>;</p></p> <p><p><span style="color:#002200;">[</span>self addspeechcontrolwithframe<span style="color:#002200;">:</span>cgrectmake<span style="color:#002200;">(</span><span style="color:#2400D9;">592</span>, <span style="color:#2400D9;">485</span>, <span style="color:#2400D9;"></span> <span style="color:#2400D9;"></span> - <span style="color:#002200;">)</span></p></p> <p><p>Title<span style="color:#002200;">:</span><em><span style="color:#11740A;">@</span></em><span style="color:#BF1D1A;">"Raise rate"</span></p></p> <p><p>Action<span style="color:#002200;">:</span><span style="color:#A61390;">@selector</span><span style="color:#002200;">(</span>raiserate<span style="color:#002200;">)]</span>;</p></p> <p><p><span style="color:#002200;">[</span>self addspeechcontrolwithframe<span style="color:#002200;">:</span>cgrectmake<span style="color:#002200;">(</span><span style="color:#2400D9;">506</span>, <span style="color:#2400D9;">555</span>, <span style="color:#2400D9;"></span> <span style="color:#2400D9;"></span> - <span style="color:#002200;">)</span></p></p> <p><p>Title<span style="color:#002200;">:</span><em><span style="color:#11740A;">@</span></em><span style="color:#BF1D1A;">"Speak Again"</span></p></p> <p><p>Action<span style="color:#002200;">:</span><span style="color:#A61390;">@selector</span><span style="color:#002200;">(</span>speakagain<span style="color:#002200;">)]</span>;</p></p> <p><p><span style="color:#002200;">}</span></p></p></td> </tr> </tbody> </table><p><p>Addspeechcontrolwithframe: the method is a convenient method. Lets you add a button to the view and connect it to the corresponding method, so that you can adjust the voice with a Button.</p></p><p><p></p></p><p><p>Note: You can also create a button in Main.storyboard and bind their action to Rwtpageviewcontroller. This is easier and more efficient.</p></p><p><p>Before Viewdidload's [self startspeaking] method, add:</p></p> <table border="0" cellpadding="0"> <tbody> <tr> <td><p><em> <span style="color:#11740A;">//1</span></em></p><p>Self.currentpitchmultiplier <span style="color:#002200;">=</span> 1.0f;</p><p>Self.currentrate <span style="color:#002200;">=</span> avspeechutterancedefaultspeechrate;</p><p><em> <span style="color:#11740A;">//2</span></em></p><p><span style="color:#002200;">[</span>self addspeechcontrols<span style="color:#002200;">]</span>;</p></td> </tr> </tbody> </table><p><p>Gaze at "1" to set the default speech Properties. The Voice control button is added to gaze at "2".</p></p><p><p></p></p><p><p>finally, Change the Speaknextutterance method:</p></p> <table border="0" cellpadding="0"> <tbody> <tr> <td><p><p><span style="color:#002200;">-</span> <span style="color:#002200;">(</span><span style="color:#A61390;">void</span><span style="color:#002200;">)</span>speaknextutterance <span style="color:#002200;">{</span></p></p> <p><p><span style="color:#A61390;">if</span> <span style="color:#002200;">(</span>self.nextspeechindex < <span style="color:#002200;">[[</span>self currentpage<span style="color:#002200;">]</span>. Utterances Count<span style="color:#002200;">])</span> <span style="color:#002200;">{</span></p></p> <p><p>Avspeechutterance <span style="color:#002200;">*</span>utterance <span style="color:#002200;">=</span> <span style="color:#002200;">[[</span>self currentpage<span style="color:#002200;">]</span>. utterances Objectatindex<span style="color:#002200;">:</span>self.nextspeechindex<span style="color:#002200;">]</span>;</p></p> <p><p>Self.nextspeechindex <span style="color:#002200;">+ =</span> <span style="color:#2400D9;">1</span>;</p></p> <p><p><em> <span style="color:#11740A;">//1</span></em></p></p> <p><p>Utterance.pitchmultiplier <span style="color:#002200;">=</span> self.currentpitchmultiplier;</p></p> <p><p><em> <span style="color:#11740A;">//2</span></em></p></p> <p><p>Utterance.rate <span style="color:#002200;">=</span> self.currentrate;</p></p> <p><p><span style="color:#002200;">[</span>self.synthesizer speakutterance<span style="color:#002200;">:</span>utterance<span style="color:#002200;">]</span>;</p></p> <p><p><span style="color:#002200;">}</span></p></p> <p><p><span style="color:#002200;">}</span></p></p></td> </tr> </tbody> </table><p><p>Suppose you clicked the Lower/raise Button. The newly set value will be applied in the next sentence read aloud.</p></p><p><p></p></p><p><p>Compile Execution. For example, as seen in:</p></p><p><p></p></p><p><p></p></p><p><p>Touch or click on these buttons, then note the changes in Pronunciation.</p></p><p><p>Yoda is really powerful, even if you are not a Jedi can become a master (avspeechsynthesizer).</p></p><p><p></p></p><p><p><strong>End</strong></p></p><p><p><span style="color:blue;">The complete project code</span> can be downloaded Here.</p></p><p><p>Hopefully this article will be the motivation to inspire you to develop your own audio books. Suppose you want to know a lot of other tips on how to tune synthetic speech, see the Following:</p></p><p><p><em>Best Audio Book Whirlysquirrelly.plist contest</em></p></p><p><p></p></p><p><p>Note: please try to further tune the whirlysquirrelly.plist and upload it to the forum or message in this Article.</p></p><p><p>We will review the winners and compliment them in the Comments.</p></p><p><p><em>Consent to user selection of books</em></p></p><p><p>Description: Add a "Choose book" Button. and displays an optional list of books in the Uipopovercontroller. When the user selects a book, resets the book object in Rwtpageviewcontroller and displays the new books.</p></p><p><p><em>Download books from the Web</em></p></p><p><p>Description: Store Books in plist format in webserver or provide services similar to AWS S3 or Heroku. The server first provides a list of Urls. List all the books and then provide a service to download a Book.</p></p><p><p>In the previous feature, add a link to the Book.</p></p><p><p><em>Read the word highlighting</em></p></p><p><p>Tip: use the method in Avspeechsynthesizerdelegate trust</p></p><p><p>In the Speechsynthesizer:didstartspeechutterance: method. Highlight the specified utterance.</p></p><p><p></p></p><p><p>In the Speechsynthesizer:didfinishspeechutterance: method. Highlight the highlighted Utterance. You can use the Pagetextlable Attributedtext property to set different background colors and font properties for the highlight effect by nsattributedstring.</p></p><p><p></p></p><p><p><em>Show title on the first page</em></p></p><p><p><em>Addthe ability to Display a Title Page before all other Pages</em></p></p><p><p>Description: add additional Viewcontroller before rwtpageviewcontroller, and set main.storyboard new property is enabled Viewcontroller. They both Viewcontroller with Uinavigationcontroller. To do this, you can change the design of the page class and divide it into the sound page and the silent page, and then change Rwtpageviewcontroller we can use these two different processing page.</p></p><br> <p><p> How to use Avspeechsynthesizer National audiobooks for IOS 7 (4) </p> </p></span>

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.