https://github.com/kilianb/googletranslatortts
Converts a string of text to mp3 files utilizing the google translator text to speech api. Fast prototyping library without fees or rate limit.
https://github.com/kilianb/googletranslatortts
java text-to-speech tts
Last synced: about 1 year ago
JSON representation
Converts a string of text to mp3 files utilizing the google translator text to speech api. Fast prototyping library without fees or rate limit.
- Host: GitHub
- URL: https://github.com/kilianb/googletranslatortts
- Owner: KilianB
- License: mit
- Created: 2017-07-12T11:38:20.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-10-05T14:09:59.000Z (almost 8 years ago)
- Last Synced: 2025-04-05T10:11:17.253Z (over 1 year ago)
- Topics: java, text-to-speech, tts
- Language: Java
- Homepage:
- Size: 79.1 KB
- Stars: 5
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Google-Text-To-Speech-Java-API
[  ](https://bintray.com/kilianb/maven/GoogleTranslatorTTS/_latestVersion)
Convert long strings of text into .mp3 files in real time utilizing googles translator text to speech service. Supports multi-language- requests and multi-threading resulting in usually responds times of < .75 seconds.
- Lightweight
- No dependencies
While stable during the past time the translator endpoint by google is undocumented and subject to change without any notification. This library
works great for private projects and quick prototyping where ever text to speech without quote limit or fees is needed. When implementing
a commercial or large scale project please consider falling back to one of the official text to speech libraries
e.g. Google Cloud, Microsoft Azure, Amazon web services.
## Maven, Gradly, Ivy
Hosted on bintray.
````
jcenter
https://jcenter.bintray.com/
github.com.kilianB
GoogleTranslatorTTS
1.0.1
````
## Example usage
```java
public class TextToSpeechSample{
public static void main(String[] args) {
// 1. Simple TTS Request
//Path to output mp3 directory
String outputPath = "mpFiles/";
//Text to convert to mp3
String text = "When in the Course of human events it becomes necessary for one people to dissolve the political bands which have connected them with another and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.";
//Create directory
File outputDirectory = new File(outputPath);
outputDirectory.mkdirs();
//Convert the text and retrieve an mp3 file
GoogleTextToSpeech tts = new GoogleTextToSpeech(outputPath);
File convertedTextMP3 = tts.convertText(text, GLanguage.English_US, "FileName");
// 2. Asnch non blocking TTS
//Non blocking method. Call event handler in the observer upon finishing
boolean deleteTemporaryFiles = true;
GoogleTextToSpeechObserver callback = new GoogleTextToSpeechAdapter() {
@Override
public void mergeCompleted(File f,int id) {
System.out.println("File available for playback: " + f.getAbsolutePath());
}
};
tts.convertTextAsynch(text,GLanguage.German, "FileNameAsynch",deleteTemporaryFiles,callback);
// 3. Multi language query
//Request an mp3 file with multiple different pronounciations
String textMult[] = new String[]{
"The author",
"Immanuel Kant",
"argued that the human mind creates the structure of human experience, that reason is the source of morality."
};
GLanguage[] language = new GLanguage[] {
GLanguage.English_GB,
GLanguage.German,
GLanguage.English_GB
};
convertedTextMP3 = tts.convertTextMultiLanguage(textMult,language,"FileNameMulti");
}
}
```