There are more than 7,000 languages spoken in the world today.
With such diversity comes a need to learn them so we can understand each other.
jot down or speak your sentence and a program can convert it into your desired language.
What Is Googletrans?
You may encounter problems relating to the version of googletrans you install.
If you see errors when running these examples, try installing version 3.1.0a0, i.e.pip install googletrans==3.1.0a0.
Googletrans supports a variety of languages for conversion.
To detect the language, importTranslatorpresent in thegoogletransmodule and create its instance.
Use thedetect()method and pass a string in any desired language.
Display the output using theprint()statement.
Create an instance ofTranslator.
Thetranslate()method automatically detects and translates your text into your desired language.
Display the translated text.
This displays the source language, the destination language, and the translated text.
you’re able to use the text function to only display the translated text.
To perform this import the required module and create an instance ofTranslator.
To do so, import thespeech recognitionmodule with an alias asspr.
Importosto save the audio file.
Use thewithstatement as a part of exception handling.
With the microphone object as source, perform these actions.
Initialize the translator object for translation.
Set the source and your desired destination language.
Inform the user to speak something using the print statement.
Use theadjust_for_ambient_noise()method to calibrate for the first time it starts listening.
Calibrating this will set this threshold to a lower value automatically.
Use the listen property to record a single phrase.
The program records the voice until there are seconds of silence or no more audio input.
Userecognize_google()to use the Google Web API and recognize the speech from the audio source.
Alternatively, you’ve got the option to use Bing, IBM, Sphinx and Wit too.
Display the phrase recognized from the audio.
Pass the sentence, the source language and the destination language to thetranslate()function.
Display the translated text by calling the text parameter and display it using theprintstatement.
Finally, usegTTSto convert the text to speech.
Pass the text, the language to read in and optionally set the slow parameter to false.
Save the voice as an mp3 file and use theosmodule to initiate the saved audio file.
The final line of this program requires thestartcommand to play the mp3 file.
You may need to substitute this with a different command, depending on your local environment.
For example, on macOS, it’s possible for you to use theafplaycommand.
These are free, support many platforms, and may fit better for your use.