forked from mayankchaudhary26/HacktoberFest-Practice-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLanguage Translater.py
More file actions
44 lines (36 loc) Β· 1.34 KB
/
Language Translater.py
File metadata and controls
44 lines (36 loc) Β· 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#install the google translator library from the Command Prompt=>
#pip install googletrans
#pip install SpeechRecognition
#pip install PyAudio (facing problem may need cracked version)
#pip install gTTS
import googletrans
from googletrans.client import Translator
import speech_recognition as sr
import gtts
import playsound
recognizer=sr.Recognizer()
#prints the list of all languages accessible by Google Translator
print(googletrans.LANGUAGES)
#making the tranlator
translator=googletrans.Translator()
print("List of all languages accessed by Google Translater")
required_language=input("Enter your choosen language code in which you want to translate:")
try:
with sr.Microphone() as source:
print("Speak Now........")
voice=recognizer.listen(source)
text=recognizer.recognize_google(voice)
print(text)
except:
pass
#create the translated text
translated=translator.translate(text,dest=required_language)
print(translated.text)
#we might get error
#install the alpha version of the package from Command Prompt=>
#pip install googletrans==3.1.0a0
#convert the translated text to audio file
required_audio=gtts.gTTS(translated.text,lang=required_language)
required_audio.save("Converted Audio.mp3")
#playing the converted audio file
playsound.playsound("Converted Audio.mp3")