Skip to content

Commit ad21d4e

Browse files
authored
Merge pull request #302 from pyerie/main
Create real-time speech translator
2 parents d5bc494 + cd552b1 commit ad21d4e

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

R/Real time translator/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Real-time language translator using Python #
2+
3+
Hi there!
4+
5+
## How it works ##
6+
7+
This program uses the ```speech_recognition``` and ```deep_translator``` libraries to convert speech to text and translate it to the desired language.
8+
9+
## Installation and usage ##
10+
11+
1) Install dependencies
12+
13+
```
14+
pip3 install speech_recognition
15+
pip3 install deep_translator
16+
pip3 install pyaudio
17+
```
18+
19+
2) Run the program
20+
21+
```
22+
python3 real_time_translator.py
23+
```
24+
25+
3) Enjoy!
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import speech_recognition as sr
2+
from deep_translator import GoogleTranslator as translator
3+
4+
recognizer = sr.Recognizer()
5+
with sr.Microphone() as source:
6+
recognizer.adjust_for_ambient_noise(source)
7+
with sr.Microphone() as source:
8+
print("Listening....")
9+
audio = recognizer.listen(source)
10+
try:
11+
text = recognizer.recognize_google(audio)
12+
print("What you spoke in English is:",text)
13+
lang = input("Which language should I translate it to?: ")
14+
translated = translator(source='auto', target=lang).translate(text)
15+
print("The content in",lang,"is:",translated)
16+
except:
17+
print("Encountered an error!")

0 commit comments

Comments
 (0)