Recently, I need to use the voice broadcast function. Taking into account accuracy and professionalism in Baidu Seven Weapons Baidu Voice and iFLYTEK's voice, iFLYTEK was selected. There are two types of Android development SDK provided by iFLYTEK. One is the SDK that integrates its own product voice+, which has relatively powerful functions but will initialize the voice service module; the other is the pure development SDK that does not integrate products, and only needs to import the corresponding jar package to use. Considering that only the technique of speech synthesis is used, the second SDK was chosen.
The specific code is as follows:
private SpeechSynthesizer mTts; private int isSpeaking = 0; mTts= (this, null); /* * Start synthesis * * @param view */ public void start() { (SpeechConstant.VOICE_NAME, "xiaoyan"); (, "50");//Set the speech speed (, "80");//Set volume, range 0~100 (SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD); //Set up the cloud (search_word_content.getText().toString().trim(), mSynListener); } //Synthetic listener private SynthesizerListener mSynListener = new SynthesizerListener(){ //Buffer progress callback //% is buffering progress 0~100, beginPos is the start position of buffering audio in text, endPos means buffering audio in text //The end position in the text, info is additional information. @Override public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) { // TODO Auto-generated method stub } //When the session ends callback interface, if there is no error, error is null @Override public void onCompleted(SpeechError arg0) { // TODO Auto-generated method stub } //Session event callback interface @Override public void onEvent(int arg0, int arg1, int arg2, Bundle arg3) { // TODO Auto-generated method stub } //Start playback @Override public void onSpeakBegin() { // TODO Auto-generated method stub } //Pause playback @Override public void onSpeakPaused() { // TODO Auto-generated method stub } //Play progress callback //Percent is the playback progress 0~100, beginPos is the start position of the playback audio in the text, endPos means the playback audio in the text //The end position in this article. @Override public void onSpeakProgress(int arg0, int arg1, int arg2) { // TODO Auto-generated method stub } //Restore playback callback interface @Override public void onSpeakResumed() { // TODO Auto-generated method stub } }; if (isSpeaking == 0) { start(); gif_no.setVisibility(); (); isSpeaking = 1; } else if (isSpeaking == 1) { // Pause playback (); gif_no.setVisibility(); (); isSpeaking = 2; } else if (isSpeaking == 2) { // Continue to play //(".........."); (); isSpeaking = 1; gif_no.setVisibility(); (); } // Cancel the synthesis (); isSpeaking = 0;
Summary, start initialization, set parameters in the start method, and then call the stop and continue methods as needed. If the text is changed, cancel the synthesis method and restart the start method.
The above content is the full narrative of using iFLYTEK Voice SDK to achieve online synthesizing of text. I hope you like it.