Swift development of text content to voice

Source: Internet
Author: User


Swift developed the text content to voice, only to convert the online OC version to the SWIFT version, the need for students to take.

Xcode7

The code is as follows Copy Code

swift2.0

Import Uikit
Import Avfoundation

Class Viewcontroller:uiviewcontroller {

Override Func Viewdidload () {
Super.viewdidload ()


Let audiosession = Avaudiosession.sharedinstance ()
do {
Try Audiosession.setcategory (Avaudiosessioncategoryplayback)
}catch let error as nserror{
Print (Error.code)
}


Let av = avspeechsynthesizer.init ()
Let Utterance1 = Avspeechutterance.init (string: "Hefei Forum is opened by Hefei Hotline website
The portal community is also the first living community in Anhui Province. Hefei Hotline by the Hefei Fertilizer Network Technology Co., Ltd. was founded in 2003,
Anhui is the first city portal. After 10 years of operation, Hefei Forum has become the largest forum in the province, the number of users,
The best word of mouth, community services, the most comprehensive community. The forum has nearly 2.3 million of the official registered members, a daily view of more than 4 million times
, with more than 70000 people online. 2006, Hefei Forum has become one of China's hundred strong network community. ")
Utterance1.postutterancedelay = 0.5
Utterance1.rate = 0.1
Av.speakutterance (Utterance1)

Do no additional setup after loading the view, typically from a nib.
}

    override func didreceivememorywarning () {
        Super.didreceivememorywarning ()
       //Dispose of any of the CAN Recreated.
   }
}

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.