TaiYouWeb commited on
Commit
15ad32c
·
verified ·
1 Parent(s): 48b5bc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -12
app.py CHANGED
@@ -29,7 +29,7 @@ model = AutoModel(
29
  device=device,
30
  )
31
 
32
- def transcribe_audio(file, 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,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
- with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as temp_file:
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="file"), # 上传音频
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"),