Please respect other people's labor results, reproduced please specify the source:"Android Voice synthesis TTS" Baidu Voice Access method, and the use of tips detailed
Ps.
Relying on Baidu Open cloud, Baidu Voice for Partners to provide industry-leading, permanent free voice technology services, Currently on-line services include speech recognition, semantic analysis, speech synthesis, follow-up will continue to bring open resources, multiple rounds of dialogue and other technical services, through the sdk " rest API and offline development package and other services to meet the development needs of different developers.
at present, the voice of Baidu provides free voice access, voice synthesis quality is fair, but not yet open offline TTS .
Service Access Process
specific details can be found at: http://yuyin.baidu.com/dev.php
Integrated Development
Import Baidu Voice related jar package and so file
Tips:
will be in the development package Libs directory is copied to the project directory, libs for each platform. so library, developer view Application need to be able to be truncated. galaxy_lite.jar is Baidu Android public base library, if the project also integrates other Baidu SDK PUSHSDK
[2013-10-22 11:02:57-dex Loader] Unableto Execute dex:multiple dex files definelcom/baidu/android/common/logging/configuration; [2013-10-22 11:02:57-voicerecognitiondemo] Conversion to Dalvik format failed:unable to executedex:multiple dex files define Lcom/baidu/android/common/logging/conf Iguration;
please add this Jar package is removed. If the Eclipse ADT version plug-in is below , you need to add the dependent library manually by adding:Project = Properties = Java Build Path = Libraries = Addjar ... 3
for ease of use I'm here to make a further package of the Baidu speech synthesis engine, encapsulated into Speechutil to facilitate invocation:
Package Com.jph.tts;import Android.content.context;import Android.media.audiomanager;import android.util.Log; Import Com.baidu.speechsynthesizer.speechsynthesizer;import Com.baidu.speechsynthesizer.speechsynthesizerlistener;import com.baidu.speechsynthesizer.publicutility.speecherror;/** * Speech Synthesis Tool class * * @author JPH * @date 2015-4-14 pm 1:33:37 */public Class Speechutil implements Speechsynthesizerlistener {protected static final int ui_log_to_view = 0;private speechsynthe Sizer Speechsynthesizer;private Context Context;public speechutil (context activity) {This.context = Activity;init ();} /** * Initialization of composition related components * * @author JPH * @date 2015-4-14 pm 1:36:53 */private void init () {SpeechSynthesizer = new Speechsynthesi Zer (context, "Holder", this);// Here you need to replace the two parameters of the Setapikey method with the ApiKey and Secretkeyspeechsynthesizer.setapikey ("Your ApiKey") that you received in the Baidu Developer Center registration application, your Secretkey "); Speechsynthesizer.setaudiostreamtype (Audiomanager.stream_music);//activity.setvolumecontrolstream ( Audiomanager.stream_music); SetParams ();} /* * Start text synthesis and read aloud * @author JPH * @date 2015-4-14 pm 1:47:05 * @param content */public void speak (final String content) {New Thread (New Runnable () {@Override public void run () {//SetParams (); int ret = Speechsynthesizer.speak (content.tostring ()); if (ret! = 0) {log.e ("INF", "Start synthesizer failed:" +ret); }}). Start ();} /** * Cancel this composition and stop reading * @author JPH * @date 2015-4-14 pm 2:20:33 */public void Cancle () {speechsynthesizer.cancel ();} /** * Pause text aloud, if no Speak (String) method is called or the synthesizer fails to initialize, the method will have no effect * @author JPH * @date 2015-4-14 pm 2:21:07 */public void Pause () {SP Eechsynthesizer.pause ();} /** * Continue text aloud, if no call to speak (String) method or synthesizer initialization fails, the method will have no effect * @author JPH * @date 2015-4-14 pm 2:21:29 */public void Resume () {s Peechsynthesizer.resume ();} /** * Set relevant parameters for the speech synthesizer * @author JPH * @date 2015-4-14 pm 1:45:11 */private void SetParams () {Speechsynthesizer.setparam (Speech Synthesizer.param_speaker, "0");//HairSpeaker, currently supports female (0) and male (1) speechsynthesizer.setparam (Speechsynthesizer.param_volume, "9");//volume, value range [0, 9], the larger the value, The larger the volume Speechsynthesizer.setparam (speechsynthesizer.param_speed, "5");//reading speed, value range [0, 9], the greater the value, The faster the speed Speechsynthesizer.setparam (Speechsynthesizer.param_pitch, "5");//pitch, value range [0, 9], the greater the value, The higher the volume Speechsynthesizer.setparam (SPEECHSYNTHESIZER.PARAM_AUDIO_ENCODE,SPEECHSYNTHESIZER.AUDIO_ENCODE_AMR);//Audio format , support Bv/amr/opus/mp3, value see subsequent constant declaration Speechsynthesizer.setparam (speechsynthesizer.param_audio_rate, SPEECHSYNTHESIZER.AUDIO_BITRATE_AMR_15K85);//audio bitrate, the bit rates supported by each audio format are described in the following constant declaration} @Overridepublic void Onstartworking ( SpeechSynthesizer synthesizer) {log.i ("msg", "Start working, please wait for data ..."); @Overridepublic void Onspeechstart (SpeechSynthesizer synthesizer) {log.i ("msg", "Start Aloud");} @Overridepublic void Onspeechresume (SpeechSynthesizer synthesizer) {log.i ("msg", "Continue reading Aloud");} @Overridepublic void onspeechprogresschanged (SpeechSynthesizer synthesizer,int progress) {//TODO auto-generated Method stub} @Overridepublic void Onspeechpause (SpeechsyNthesizer synthesizer) {log.i ("msg", "read aloud paused");} @Overridepublic void Onspeechfinish (SpeechSynthesizer synthesizer) {log.i ("msg", "read aloud stopped");} @Overridepublic void Onnewdataarrive (SpeechSynthesizer synthesizer,byte[] Audiodata, Boolean islastdata) {log.i ("msg") , "New audio data:" + audiodata.length+ (islastdata? "(end)": "")); @Overridepublic void OnError (SpeechSynthesizer synthesizer, speecherror error) {log.i ("msg", "Error occurred:" + Error.errordescription + "(" + error.errorcode+ ")");} @Overridepublic void OnCancel (SpeechSynthesizer synthesizer) {log.i ("msg", "Canceled");} @Overridepublic void onbufferprogresschanged (SpeechSynthesizer synthesizer,int progress) {//TODO auto-generated Method stub}}
How to use:
Package Com.jph.tts;import Android.app.activity;import Android.os.bundle;import Android.text.method.scrollingmovementmethod;import Android.view.view;import Android.view.View.OnClickListener; Import Android.widget.button;import Android.widget.edittext;import Android.widget.textview;import Com.baidu.tts.sample.r;public class Homeactivity extends Activity implements Onclicklistener {protected static final int Ui_log_to_view = 0;private TextView logview;private EditText inputtextview;private Button startbutton;private Speechutil speechutil; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_home); LogView = (TextView) Findviewbyid (R.id.logview); Logview.setmovementmethod (New Scrollingmovementmethod ()); Inputtextview = (EditText) Findviewbyid ( R.id.inputtextview); speechutil = new Speechutil (this);} @Override public void OnClick (View v) {switch (V.getid ()) {R.id.btnstart:speechutil.speak ( InchPuttextview.gettext (). toString ()); Break Case R.id.btnpause:speechutil.pause (); Break Case R.id.btnresume:speechutil.resume (); Break Case R.id.btnstop:speechutil.cancle (); Break Default:break; } }}
because Baidu TTS Network parsing is required so that the appropriate permissions are given to the app:
<uses-permission android:name= "Android.permission.INTERNET" ></uses-permission> < Uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE" ></uses-permission> < Uses-permission android:name= "Android.permission.READ_PHONE_STATE"/>
Recommended reading:
"Android Speech TTS" domestic mainstream engine comparison
"Android Speech synthesis TTS" cloud-aware offline TTS using detailed
"Android Voice synthesis TTS" Baidu Voice Access method, and the use of tips detailed