Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
3 |
|
4 |
def recognize_speech(audio):
|
5 |
-
|
6 |
-
|
7 |
-
audio_data = recognizer.record(source)
|
8 |
-
try:
|
9 |
-
text = recognizer.recognize_google(audio_data, language='zh-TW') # 使用 Google 語音識別
|
10 |
-
return text
|
11 |
-
except sr.UnknownValueError:
|
12 |
-
return "無法識別語音"
|
13 |
-
except sr.RequestError:
|
14 |
-
return "無法連接到語音識別服務"
|
15 |
|
16 |
iface = gr.Interface(fn=recognize_speech, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text", title="語音轉文字應用", description="請說話,然後按下停止按鈕進行文字轉換。")
|
17 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# 創建語音識別的 pipeline
|
5 |
+
asr = pipeline("automatic-speech-recognition")
|
6 |
|
7 |
def recognize_speech(audio):
|
8 |
+
result = asr(audio)
|
9 |
+
return result['text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
iface = gr.Interface(fn=recognize_speech, inputs=gr.Audio(source="microphone", type="filepath"), outputs="text", title="語音轉文字應用", description="請說話,然後按下停止按鈕進行文字轉換。")
|
12 |
iface.launch()
|