Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

voice translate python

from pyttsx3 import engine
import speech_recognition as sr
from google_trans_new import google_translator
import pyttsx3

def speak(audio):
    engine.say(audio)
    engine.runAndWait()

recognizer = sr.Recognizer()
engine = pyttsx3.init()

with sr.Microphone() as source:
    print("Please say something.")
    speak("Please say something.")
    recognizer.adjust_for_ambient_noise(source,duration=1)
    audio  = recognizer.listen(source,timeout=1)
    print("Done recording")
    speak("Done recording")


try:
    print("recognizing...")
    speak("recognizing...")
    result = recognizer.recognize_google(audio,language='en')
except Exception as ex:
    print(ex)
    speak(ex)


#Translation function
def trans():
    langinput = input("Type the language code you want to translate:")
    speak("Type the language code you want to translate:")
    translator = google_translator()
    translate_text = translator.translate(str(result),lang_tgt=str(langinput))
    print(translate_text)
    speak(translate_text)
    engine.say(str(translate_text))
    engine.runAndWait()
trans()
Comment

PREVIOUS NEXT
Code Example
Python :: how to find the closest value in column python 
Python :: python 3.8.5 download 32 bit 
Python :: adding roles discord py 
Python :: python recursively merge dictionaries 
Python :: blender scripting set active ojbect 
Python :: Python Roman to Integer method 2 
Python :: django slug int url mapping 
Python :: python sort the values in a dictionaryi 
Python :: python arguments 
Python :: play video in colab 
Python :: python string remove accent 
Python :: how to sort a list descending python 
Python :: python run in another thread decorator 
Python :: count most frequent words in list python 
Python :: get count of values in column pandas 
Python :: python array colon 
Python :: inverse matrix python numpy 
Python :: edit pandas row value 
Python :: detect character in string python 
Python :: Custom x, y-ticks using plt 
Python :: make button bigger tkinter with grid 
Python :: seed python 
Python :: find max value in list python 
Python :: python variable 
Python :: input in one line python 
Python :: tkinter 
Python :: find sum numbers in a list in python 
Python :: python append csv to dataframe 
Python :: python variable declare 
Python :: strip in python 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =