Xunfei speech synthesis Example 2

Source: Internet
Author: User

Note: offline speech synthesis and online speech synthesis can be realized.

The mainactivity. Java code is as follows:

Package COM. chen. test16; import android. app. activity; import android. OS. bundle; import android. OS. remoteException; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. textview; import COM. iflytek. speech. ispeechmodule; import COM. iflytek. speech. initlistener; import COM. iflytek. speech. speechconstant; import COM. iflytek. speech. speechsynthesizer; import COM. iflytek. speech. speechutility; import COM. iflytek. speech. synthesizerlistener; public class mainactivity extends activity {private textview; private button; speechsynthesizer MTTS; @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); textview = (textview) findviewbyid (R. id. textview); button = (button) findviewbyid (R. id. button); button. setonclicklistener (New buttonlistener (); If (speechutility. getutility (this ). queryavailableengines () = NULL | speechutility. getutility (this ). queryavailableengines (). length <= 0) {textview. settext ("Download");} speechutility. getutility (this ). setappid ("51b6eedb"); MTTS = new speechsynthesizer (this, mttsinitlistener);} class buttonlistener implements onclicklistener {@ overridepublic void onclick (view V) {// todo auto-generated method stubmtts. setparameter (speechconstant. engine_type, "local"); MTTS. setparameter (speechsynthesizer. voice_name, "Xiaoyan"); MTTS. setparameter (speechsynthesizer. speed, "50"); MTTS. setparameter (speechsynthesizer. pitch, "50"); int code = MTTS. startspeaking ("KEDA xunfei speech synthesis", mttslistener) ;}} private initlistener mttsinitlistener = new initlistener () {@ overridepublic void oninit (ispeechmodule arg0, int code) {// todo auto-generated method stub}; synthesizerlistener mttslistener = new synthesizerlistener. stub () {@ overridepublic void onspeakresumed () throws RemoteException {// todo auto-generated method stub} @ overridepublic void onspeakprogress (INT progress) throws RemoteException {// todo auto-generated method stub} @ overridepublic void onspeakpaused () throws RemoteException {// todo auto-generated method stub} @ overridepublic void onspeakbegin () throws RemoteException {// todo auto-generated method stub} @ overridepublic void oncompleted (INT code) throws RemoteException {// todo auto-generated method stub} @ overridepublic void onbufferprogress (INT progress) throws RemoteException {// todo auto-generated method stub }};}

Note: First paste the speechapi. jar file in the/libs directory.

Import the existing speechapi. jar file to the project.

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.