Abigail99216 commited on
Commit
e572754
·
verified ·
1 Parent(s): 1c15adb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -31,7 +31,7 @@ def transcribe(audio):
31
  global current_speaker
32
  if audio is None:
33
  logging.info("No audio input received")
34
- return "No audio input received"
35
 
36
  try:
37
  logging.info(f"Audio input received: {type(audio)}")
@@ -61,10 +61,10 @@ def transcribe(audio):
61
  logging.info(f"Transcription result: {text}")
62
  except Exception as e:
63
  logging.error(f"Error during transcription: {e}", exc_info=True)
64
- return f"Transcription error: {str(e)}"
65
  else:
66
  logging.error("Transcriber not initialized")
67
- return "Transcriber not initialized"
68
 
69
  # 创建结构化数据
70
  if text:
@@ -84,7 +84,7 @@ def transcribe(audio):
84
  return formatted_conversation
85
  except Exception as e:
86
  logging.error(f"Error in transcribe function: {e}", exc_info=True)
87
- return f"Error: {str(e)}"
88
 
89
  def switch_speaker():
90
  global current_speaker
@@ -132,7 +132,7 @@ with gr.Blocks() as demo:
132
  gr.Markdown("点击麦克风图标开始录音,说话后会自动进行语音识别。支持中文识别。")
133
 
134
  with gr.Row():
135
- audio_input = gr.Audio(sources=["microphone"], type="numpy")
136
  speaker_button = gr.Button("切换说话者")
137
 
138
  speaker_label = gr.Label("当前说话者:患者")
 
31
  global current_speaker
32
  if audio is None:
33
  logging.info("No audio input received")
34
+ return json.dumps({"error": "No audio input received"})
35
 
36
  try:
37
  logging.info(f"Audio input received: {type(audio)}")
 
61
  logging.info(f"Transcription result: {text}")
62
  except Exception as e:
63
  logging.error(f"Error during transcription: {e}", exc_info=True)
64
+ return json.dumps({"error": f"Transcription error: {str(e)}"})
65
  else:
66
  logging.error("Transcriber not initialized")
67
+ return json.dumps({"error": "Transcriber not initialized"})
68
 
69
  # 创建结构化数据
70
  if text:
 
84
  return formatted_conversation
85
  except Exception as e:
86
  logging.error(f"Error in transcribe function: {e}", exc_info=True)
87
+ return json.dumps({"error": f"Error: {str(e)}"})
88
 
89
  def switch_speaker():
90
  global current_speaker
 
132
  gr.Markdown("点击麦克风图标开始录音,说话后会自动进行语音识别。支持中文识别。")
133
 
134
  with gr.Row():
135
+ audio_input = gr.Audio(sources=["microphone"], type="numpy", sample_rate=16000)
136
  speaker_button = gr.Button("切换说话者")
137
 
138
  speaker_label = gr.Label("当前说话者:患者")