Android studio application development integration Baidu voice synthesis application method example explanation

First, speech synthesis refers to converting text information into sound. It means to turn text into sound and let your application speak. Baidu voice and iFLYTEK are well-known third-party speech synthesis platforms in the industry in China.

This paper integrates Baidu speech synthesis, which is mainly characterized by:

Completely free forever

The industry's first completely permanent free new form provides developers with the most smooth and natural speech synthesis services. Completely free, permanent use, completely free of restrictions.

Offline online fusion mode

The SDK can automatically determine whether to use a local engine or a cloud engine for voice synthesis according to the current network conditions, so you don't have to worry about traffic consumption anymore!

Multi language and multi tone options

You can choose Mandarin, mixed Chinese and English, male voice and female voice. It also supports the setting of speech speed, tone, volume and audio code rate, so that your application has the sweetest and most magnetic voice!

Smooth and natural synthetic effect

Speech synthesis technology is leading in the industry. The synthesis effect is close to that of real people. It is smooth, natural and highly expressive, giving you the most comfortable hearing experience!

The official demo of Baidu voice is written in the eclipse environment, but it is a little different in Android studio. Please see the detailed steps of Baidu voice synthesis (step-by-step operation, don't jump, impatient, can't eat hot tofu):

1. Register Baidu voice Developer Platform

Registering baidu account, registering developer information and creating an application can get app ID, API key and secret key. These three values will be used for authorization (very key) during the development process to open voice synthesis service. If you need to use offline synthesis function, you also need to apply for offline authorization. Please see Baidu voice access process for detailed steps.

Key value view (key)

2. Download resources

Download Baidu voice SDK according to your own needs. This sample downloads the off-line integrated voice synthesis SDK_ Android version, address: http://yuyin.baidu.com/tts/download

3. Integrated Baidu voice guide

3.1 add jar package and so library to the project

Copy the LIBS directory in the development package to the project directory (eclipse users). The LIBS directory includes jar packages and so libraries of each platform. Developers can delete it according to application needs. galaxy_ lite. Jar is the public basic library of Baidu Android. If other Baidu SDKs, such as push SDK, are integrated into the project, the following error messages appear in the packaging process:

[2013-10-22 11:02:57 - Dex Loader] Unable to execute dex: Multiple dex files define Lcom/baidu/android/common/logging/Configuration; [2013-10-22 11:02:57 - VoiceRecognitionDemo] Conversion to Dalvik format Failed: Unable to execute dex: Multiple dex files define Lcom/baidu/android/common/logging/Configuration;

Please remove this jar package. For users using Android studio, you should put the jar package in the LIBS directory under the LIBS directory, and then add library dependencies (don't forget), instead of The so library should be placed in the jnilibs directory, which is in the same directory as Java and res. If there is no corresponding directory, create it yourself. The whole structure is shown in the figure below:

3.2 add speech synthesis resource file

Put the dat file under the data directory in the development package into the assets directory of the project. The assets directory is in the same directory as Java and res for use when setting resource file parameters.

3.3 authority statement

To use Baidu voice, you need to declare the following permissions:

4. Speech synthesis function code

4. 1 TTS initialization

Note: before initializing settings, copy the resource files in the assets folder to the SD card for use. In addition, the validity period of offline authorization temporary files is only 30 days. If you want to use voice offline synthesis for a long time, you should open offline authorization in application management.

4. 2 synthesize and play

mSpeechSynthesizer. speak(text);

The interface is time-consuming and adopts queuing strategy. After calling, it will automatically join the synthesis queue, and synthesize and play according to the calling order.

Well, now your speech synthesis can be used. If you want to set more parameters, please see the official development document and Development Manual of Baidu speech synthesis.

5. Source code

Finally, paste my source code.

Manifest file: androidmanifest xml

Layout files: activity_ main. xml

Java: MainActivity. java

The above is an example of how to use Android studio application development integration Baidu speech synthesis introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>