Spaces:
Sleeping
Sleeping
first version
Browse files- .gitignore +2 -0
- app.py +25 -4
- requirements.txt +3 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.env
|
2 |
+
flagged/*
|
app.py
CHANGED
@@ -1,7 +1,28 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
def greet(name):
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
|
|
|
|
|
5 |
|
6 |
+
# # 设置你的OpenAI API密钥
|
7 |
+
# openai.api_key = "your_openai_api_key"
|
8 |
+
|
9 |
+
# 定义将音频转换为文本的函数
|
10 |
+
def transcribe_audio(audio):
|
11 |
+
os.rename(audio, audio + '.wav')
|
12 |
+
audio_file = open(audio + '.wav', "rb")
|
13 |
+
# 调用Whisper API进行语音识别
|
14 |
+
transcript = openai.Audio.transcribe("whisper-1", audio_file)
|
15 |
+
|
16 |
+
# 返回识别的文字
|
17 |
+
return transcript["text"]
|
18 |
+
|
19 |
+
# 创建Gradio界面
|
20 |
+
audio_input = gr.inputs.Audio(source="microphone", type="filepath")
|
21 |
+
text_output = gr.outputs.Textbox()
|
22 |
+
|
23 |
+
iface = gr.Interface(fn=transcribe_audio, inputs=audio_input, outputs=text_output,
|
24 |
+
title="Whisper语音识别",
|
25 |
+
description="使用麦克风录制音频并将其转换为文本。")
|
26 |
+
|
27 |
+
# 启动Gradio应用
|
28 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
openai
|
2 |
+
ffmpeg
|
3 |
+
gradio
|