-
Notifications
You must be signed in to change notification settings - Fork 3
/
stt.py
30 lines (26 loc) · 906 Bytes
/
stt.py
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
import speech_recognition as sr
from playsound import playsound
import sys
def request():
# 음성 인식기 생성
r = sr.Recognizer()
global audio
# 마이크에서 음성 입력 받기
with sr.Microphone() as source:
print("Please tell me.")
try:
# 3초간 입력이 없다면 종료
audio = r.listen(source, timeout=3)
except sr.WaitTimeoutError:
playsound("/home/jetson/Desktop/LangChain-StoryBot-main/assist/wav/try_recognitio.wav")
request()
try:
# 음성을 텍스트로 변환
text = r.recognize_google(audio, language='ko-KR')
print(f"request : {text}")
return text
except sr.UnknownValueError:
playsound("/home/jetson/Desktop/LangChain-StoryBot-main/assist/wav/try_recognitio.wav")
request()
except sr.RequestError as e:
request()