Android speech synthesis (using the Tencent mobile sdk)

Source: Internet
Author: User

Recently, we need to use the speech broadcasting function. Considering the accuracy and professionalism of Baidu's seven weapons Baidu speech and Tencent's speech, we chose KEDA xunfei. One of the two android development sdks provided by KEDA xunfei is the integration of the voice + sdk of its own product, which is powerful but will initialize the voice service module; the other is that the pure Development sdk can be used without integrating the product by importing the corresponding jar package. Considering that only speech synthesis technology is used, the second sdk is selected.

Ps: if it weren't for the official documentation of his sdk, it would be too bad to write this article.

1. The first jar package is Msc. jar and libmsc. so files (which need to be placed in the armeabi folder ). You can download it from the official website.

2. Enter the required permissions in the AndroidManifest file.

 
 
 
 
 
 
3. Add-keep class com. iflytek. ** {*;} during obfuscation and packaging .**{*;},

4. Use in the Code:

Package com. tts. demo; import com. iflytek. cloud. errorCode; import com. iflytek. cloud. initListener; import com. iflytek. cloud. speechConstant; import com. iflytek. cloud. speechError; import com. iflytek. cloud. speechSynthesizer; import com. iflytek. cloud. speechUtility; import com. iflytek. cloud. synthesizerListener; import android. OS. bundle; import android. app. activity; import android. util. log; import android. view. menu; I Mport android. view. view; import android. view. view. onClickListener; import android. widget. button; public class MainActivity extends Activity implements OnClickListener {private SpeechSynthesizer mySynthesizer; private Button tts_Button; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); tts_Button = (Button) findViewById (R. id. tts_button); tts_Button.setOnClickListener (this ); /* When you upload an application package on The Voice platform, an appid will be automatically generated. The appid corresponding to the package should not be used after the application is submitted. * // speech initialization, you only need to initialize the application once. If this clause is not used, the 10111 initialization failure SpeechUtility will occur. createUtility (MainActivity. this, "appid = 51e8ae25"); // process the key class of speech synthesis: mySynthesizer = SpeechSynthesizer. createSynthesizer (this, myInitListener);} private InitListener myInitListener = new InitListener () {@ Overridepublic void onInit (int Code) {Log. d ("mySynthesiezer:", "InitListener init () code =" + code) ;};@ Overridepublic void onClick (View v) {// TODO Auto-generated method stubswitch (v. getId () {case R. id. tts_button: // sets the speaker mySynthesizer. setParameter (SpeechConstant. VOICE_NAME, "xiaoyan"); // sets the tone of mySynthesizer. setParameter (SpeechConstant. PITCH, "50"); // sets the volume of mySynthesizer. setParameter (SpeechConstant. VOLUME, "50"); int code = mySynthesiz Er. startSpeaking ("Welcome to speech navigation! ", MTtsListener); Log. d ("mySynthesiezer start code:", code + ""); break; default: break;} private SynthesizerListener mTtsListener = new SynthesizerListener () {@ Overridepublic void onSpeakBegin () {}@ Overridepublic void onSpeakPaused () {}@ Overridepublic void onSpeakResumed () {}@ Overridepublic void onBufferProgress (int percent, int beginPos, int endPos, String info) {}@ Overridepublic void onSpeakProgress (I Nt percent, int beginPos, int endPos) {}@ Overridepublic void onCompleted (SpeechError error) {if (error! = Null) {Log. d ("mySynthesiezer complete code:", error. getErrorCode () + "");} else {Log. d ("mySynthesiezer complete code:", "0 ");}}};}



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.