git clone https://github.com/changemyminds/Google-Cloud-TTS-Android.git
Go to here and change "YOUR_API_KEY" to your Google Cloud API Key.
debug{
buildConfigField "String", "API_KEY", "\"YOUR_API_KEY\""
}
p.s If you want test your API key by JUnit, go to here and change "YOUR_API_KEY" to test.
Note
If you don't know the Google API Key, please see Google document.
Here prompt the Google API KEY setting.
(1) Got to google console cloud dashboard
(2) Click upper left corner menu and select 'APIs & Services' choose the Credentials.
(3) Add CREATE CREDENTIALS and select API Key that will create the no restrict key.
(4) Don't forget your API-Key Application restrictions and API restrictions must select None and Don't restrict key.
Step 1. Add the JitPack repository in your root build.gradle
buildscript {
...
}
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency in your app build.gradle
android {
...
}
dependencies {
implementation 'com.github.changemyminds:Google-Cloud-TTS-Android:1.0.2'
}
See the below sample.
// Set the ApiKey and create GoogleCloudTTS.
GoogleCloudTTS googleCloudTTS = GoogleCloudTTSFactory.create("YOUR_API_KEY");
// Load google cloud VoicesList and select the languageCode and voiceName with index (0 ~ N).
VoicesList voicesList = googleCloudTTS.load();
String languageCode = voicesList.getLanguageCodes()[0];
String voiceName = voicesList.getVoiceNames(languageCode)[0];
// Set languageCode and voiceName, Rate and pitch parameter.
googleCloudTTS.setVoiceSelectionParams(new VoiceSelectionParams(languageCode, voiceName))
.setAudioConfig(new AudioConfig(AudioEncoding.MP3, 0.35f , 10f));
// start speak
googleCloudTTS.start("you want speak something");
// stop speak
googleCloudTTS.stop();
// pause speak
googleCloudTTS.pause();
// resume speak
googleCloudTTS.resume();
If you want to test voice or find support language, you can go here to test online.
Google Cloud Java Issue
Google Cloud Text-to-speech
OkHttp
Gson