Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,17 +5,15 @@ def speech_to_text(audio):
|
|
5 |
recognizer = sr.Recognizer()
|
6 |
|
7 |
with sr.AudioFile(audio.name) as source:
|
8 |
-
audio_data = recognizer.record(source)
|
9 |
try:
|
10 |
-
|
11 |
-
text = recognizer.recognize_google(audio_data, language="zh-TW") # 中文
|
12 |
return text
|
13 |
except sr.UnknownValueError:
|
14 |
return "語音無法識別"
|
15 |
except sr.RequestError:
|
16 |
return "無法連接到服務"
|
17 |
|
18 |
-
# 建立 Gradio 介面
|
19 |
iface = gr.Interface(fn=speech_to_text,
|
20 |
inputs=gr.Audio(source="upload", type="file"),
|
21 |
outputs="text",
|
|
|
5 |
recognizer = sr.Recognizer()
|
6 |
|
7 |
with sr.AudioFile(audio.name) as source:
|
8 |
+
audio_data = recognizer.record(source)
|
9 |
try:
|
10 |
+
text = recognizer.recognize_google(audio_data, language="zh-TW")
|
|
|
11 |
return text
|
12 |
except sr.UnknownValueError:
|
13 |
return "語音無法識別"
|
14 |
except sr.RequestError:
|
15 |
return "無法連接到服務"
|
16 |
|
|
|
17 |
iface = gr.Interface(fn=speech_to_text,
|
18 |
inputs=gr.Audio(source="upload", type="file"),
|
19 |
outputs="text",
|