xieli commited on
Commit
4edd06d
·
1 Parent(s): eea7b6a

feat: remove asr

Browse files
Files changed (1) hide show
  1. app.py +41 -40
app.py CHANGED
@@ -4,7 +4,7 @@ Step-Audio-EditX - Audio Editing Demo using StepFun API
4
  import logging
5
  import gradio as gr
6
 
7
- from stepfun_api import get_api_token, process_audio, transcribe_audio
8
 
9
  # Configure logging
10
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
@@ -170,53 +170,54 @@ class EditxTab:
170
  state["history_audio"] = []
171
  return [], state
172
 
173
- def auto_transcribe_audio(self, audio_path, state):
174
- """
175
- 自动转录音频文件,一次性返回最终结果
176
 
177
- Args:
178
- audio_path: 音频文件路径
179
- state: 状态字典
180
 
181
- Returns:
182
- 转录的文本内容和更新后的状态
183
- """
184
- if not audio_path:
185
- return "", state
186
 
187
- # 防止重复调用 - 简化逻辑
188
- if state.get("last_audio_path") == audio_path:
189
- self.logger.debug(f"⚠️ Skipping duplicate transcription request for: {audio_path}")
190
- return state.get("last_transcribed_text", ""), state
191
 
192
- try:
193
- # 更新音频路径
194
- state["last_audio_path"] = audio_path
195
 
196
- self.logger.info(f"🎙️ Starting auto transcription for: {audio_path}")
197
 
198
- # 使用stepfun_api中的transcribe_audio函数,不使用streaming模式
199
- transcribed_text = transcribe_audio(audio_path, streaming=False)
200
 
201
- # 转录完成,缓存结果
202
- state["last_transcribed_text"] = transcribed_text
203
 
204
- self.logger.info(f"✅ Auto transcription completed: {transcribed_text}")
205
- return transcribed_text, state
206
 
207
- except Exception as e:
208
- error_msg = f"[转录失败: {str(e)}]"
209
- self.logger.error(f"❌ Auto transcription failed: {str(e)}")
210
- state["last_transcribed_text"] = error_msg
211
- return error_msg, state
212
 
213
  def init_state(self):
214
  """Initialize conversation state"""
215
  return {
216
  "history_messages": [],
217
- "history_audio": [],
218
- "last_audio_path": None, # 用于防重复调用
219
- "last_transcribed_text": "" # 缓存最后的转录结果
 
220
  }
221
 
222
  def update_edit_info(self, category):
@@ -295,12 +296,12 @@ class EditxTab:
295
  outputs=self.edit_info,
296
  )
297
 
298
- # 音频上传时自动转录
299
- self.prompt_audio_input.change(
300
- fn=self.auto_transcribe_audio,
301
- inputs=[self.prompt_audio_input, state],
302
- outputs=[self.prompt_text_input, state]
303
- )
304
 
305
 
306
  def create_demo():
 
4
  import logging
5
  import gradio as gr
6
 
7
+ from stepfun_api import get_api_token, process_audio # transcribe_audio
8
 
9
  # Configure logging
10
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
 
170
  state["history_audio"] = []
171
  return [], state
172
 
173
+ # def auto_transcribe_audio(self, audio_path, state):
174
+ # """
175
+ # 自动转录音频文件,一次性返回最终结果
176
 
177
+ # Args:
178
+ # audio_path: 音频文件路径
179
+ # state: 状态字典
180
 
181
+ # Returns:
182
+ # 转录的文本内容和更新后的状态
183
+ # """
184
+ # if not audio_path:
185
+ # return "", state
186
 
187
+ # # 防止重复调用 - 简化逻辑
188
+ # if state.get("last_audio_path") == audio_path:
189
+ # self.logger.debug(f"⚠️ Skipping duplicate transcription request for: {audio_path}")
190
+ # return state.get("last_transcribed_text", ""), state
191
 
192
+ # try:
193
+ # # 更新音频路径
194
+ # state["last_audio_path"] = audio_path
195
 
196
+ # self.logger.info(f"🎙️ Starting auto transcription for: {audio_path}")
197
 
198
+ # # 使用stepfun_api中的transcribe_audio函数,不使用streaming模式
199
+ # transcribed_text = transcribe_audio(audio_path, streaming=False)
200
 
201
+ # # 转录完成,缓存结果
202
+ # state["last_transcribed_text"] = transcribed_text
203
 
204
+ # self.logger.info(f"✅ Auto transcription completed: {transcribed_text}")
205
+ # return transcribed_text, state
206
 
207
+ # except Exception as e:
208
+ # error_msg = f"[转录失败: {str(e)}]"
209
+ # self.logger.error(f"❌ Auto transcription failed: {str(e)}")
210
+ # state["last_transcribed_text"] = error_msg
211
+ # return error_msg, state
212
 
213
  def init_state(self):
214
  """Initialize conversation state"""
215
  return {
216
  "history_messages": [],
217
+ "history_audio": []
218
+ # # ASR相关状态(已禁用)
219
+ # "last_audio_path": None, # 用于防重复调用
220
+ # "last_transcribed_text": "" # 缓存最后的转录结果
221
  }
222
 
223
  def update_edit_info(self, category):
 
296
  outputs=self.edit_info,
297
  )
298
 
299
+ # # 音频上传时自动转录
300
+ # self.prompt_audio_input.change(
301
+ # fn=self.auto_transcribe_audio,
302
+ # inputs=[self.prompt_audio_input, state],
303
+ # outputs=[self.prompt_text_input, state]
304
+ # )
305
 
306
 
307
  def create_demo():