GithubHelp home page GithubHelp logo

sivanookala / googletranslatortts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kilianb/googletranslatortts

0.0 1.0 0.0 81 KB

Converts a string of text to mp3 files utilizing the google translator text to speech api. Fast prototyping library without fees or rate limit.

License: MIT License

Java 100.00%

googletranslatortts's Introduction

Google-Text-To-Speech-Java-API

Download

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.

<repositories>
  <repository>
    <id>jcenter</id>
    <url>https://jcenter.bintray.com/</url>
  </repository>
</repositories>

<dependency>
  <groupId>github.com.kilianB</groupId>
  <artifactId>GoogleTranslatorTTS</artifactId>
  <version>1.0.1</version>
</dependency>

Example usage

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");
    }
}

googletranslatortts's People

Contributors

kilianb avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.