Hello python programmers, This blog contains the code for voice translator using python
STEP 1: Libraries required
*pip install speech Recognition
*pip install google_trans_new
*pip install pyttsx3
STEP 2:Importing the libraries
import speech_recognition as sr
from google_trans_new import google_translator
import pyttsx3
STEP3: Creating Instances
recognizer=sr.Recognizer()
engine=pyttsx3.init()
STEP4:Recording the audio
with sr.Microphone() as source:
print('Clearing the background noises..')
recognizer.adjust_for_ambient_noise(source,duration=1)
print('Waiting for your message')
audio=recognizer.listen(source,timeout=1)
print('Done recording')
try:
print('Recognizing')
result=recognizer.recognize_google(audio,language='en')
except Exception as ex:
print(ex)
STEP5: Translation
def trans():
langinput=input('Type the language code you want to translate:')
translator=google_translator()
translate_text=translator.translate(str(result),lang_tgt=str(langinput))
print(translate_text)
engine.say(str(translate_text))
engine.runAndWait()
trans()
Fullcode: Github
Nice blog! Good informative post.
ReplyDeletePython Development Service
hire Python Developer