Python Project With Source Code - Voice Translators
Voice Translators
Dependencies:
*Google Translate*
```python
pip install googletrans
```
*pyttsx3*
```python
pip install pyttsx3
```
*pyaudio*
```python
pip install pyaudio
```
*speech recongnition*
```python
pip install SpeechRecognition
```
Source Code:
from googletrans import Translator
import pyttsx3
import speech_recognition as sr
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"AK47 Said:{query}\n")
except Exception as e:
print(e)
print("Say that again Please...")
speak("Say that again Please...")
return "None"
return query
def Translate():
speak("what I should Translate??")
sentence = takeCommand()
trans = Translator()
trans_sen = trans.translate(sentence,src='en',dest='ca')
print(trans_sen.text)
speak(trans_sen.text)
Translate()
0 Comments