Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -29,7 +29,7 @@ model = AutoModel(
|
|
29 |
device=device,
|
30 |
)
|
31 |
|
32 |
-
def transcribe_audio(
|
33 |
ncpu=4, batch_size=1, language="auto", use_itn=True, batch_size_s=60,
|
34 |
merge_vad=True, merge_length_s=15, batch_size_threshold_s=50,
|
35 |
hotword=" ", spk_model="cam++", ban_emo_unk=False):
|
@@ -37,15 +37,13 @@ def transcribe_audio(file, vad_model="fsmn-vad", vad_kwargs='{"max_single_segmen
|
|
37 |
# 将字符串转换为字典
|
38 |
vad_kwargs = json.loads(vad_kwargs)
|
39 |
|
40 |
-
#
|
41 |
-
|
42 |
-
temp_file_path = temp_file.name
|
43 |
-
temp_file.write(file.read())
|
44 |
|
45 |
try:
|
46 |
# 生成结果
|
47 |
res = model.generate(
|
48 |
-
input=temp_file_path, #
|
49 |
cache={},
|
50 |
language=language,
|
51 |
use_itn=use_itn,
|
@@ -62,18 +60,13 @@ def transcribe_audio(file, vad_model="fsmn-vad", vad_kwargs='{"max_single_segmen
|
|
62 |
text = rich_transcription_postprocess(res[0]["text"])
|
63 |
|
64 |
return text
|
65 |
-
|
66 |
-
finally:
|
67 |
-
# 确保在处理完毕后删除临时文件
|
68 |
-
if os.path.exists(temp_file_path):
|
69 |
-
os.remove(temp_file_path)
|
70 |
|
71 |
except Exception as e:
|
72 |
return str(e)
|
73 |
|
74 |
# 创建Gradio界面
|
75 |
inputs = [
|
76 |
-
gr.Audio(type="
|
77 |
gr.Textbox(value="fsmn-vad", label="VAD Model"),
|
78 |
gr.Textbox(value='{"max_single_segment_time": 30000}', label="VAD Kwargs"),
|
79 |
gr.Slider(1, 8, value=4, step=1, label="NCPU"),
|
|
|
29 |
device=device,
|
30 |
)
|
31 |
|
32 |
+
def transcribe_audio(file_path, vad_model="fsmn-vad", vad_kwargs='{"max_single_segment_time": 30000}',
|
33 |
ncpu=4, batch_size=1, language="auto", use_itn=True, batch_size_s=60,
|
34 |
merge_vad=True, merge_length_s=15, batch_size_threshold_s=50,
|
35 |
hotword=" ", spk_model="cam++", ban_emo_unk=False):
|
|
|
37 |
# 将字符串转换为字典
|
38 |
vad_kwargs = json.loads(vad_kwargs)
|
39 |
|
40 |
+
# 使用文件路径作为输入
|
41 |
+
temp_file_path = file_path
|
|
|
|
|
42 |
|
43 |
try:
|
44 |
# 生成结果
|
45 |
res = model.generate(
|
46 |
+
input=temp_file_path, # 使用文件路径作为输入
|
47 |
cache={},
|
48 |
language=language,
|
49 |
use_itn=use_itn,
|
|
|
60 |
text = rich_transcription_postprocess(res[0]["text"])
|
61 |
|
62 |
return text
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
except Exception as e:
|
65 |
return str(e)
|
66 |
|
67 |
# 创建Gradio界面
|
68 |
inputs = [
|
69 |
+
gr.Audio(type="filepath"), # 设置为'filepath'来支持文件路径
|
70 |
gr.Textbox(value="fsmn-vad", label="VAD Model"),
|
71 |
gr.Textbox(value='{"max_single_segment_time": 30000}', label="VAD Kwargs"),
|
72 |
gr.Slider(1, 8, value=4, step=1, label="NCPU"),
|