Pijush2023 commited on
Commit
f48c8f0
·
verified ·
1 Parent(s): 3a8f733

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -264,10 +264,11 @@ pipe_asr = pipeline(
264
  batch_size=16,
265
  torch_dtype=torch_dtype,
266
  device=device,
267
- return_timestamps=True
 
268
  )
269
 
270
- # Define the transcription function for streaming audio
271
  def transcribe_function(stream, new_chunk):
272
  try:
273
  sr, y = new_chunk[0], new_chunk[1]
@@ -275,7 +276,10 @@ def transcribe_function(stream, new_chunk):
275
  print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
276
  return stream, "", None
277
 
278
- y = y.astype(np.float32) / np.max(np.abs(y))
 
 
 
279
 
280
  if stream is not None:
281
  stream = np.concatenate([stream, y])
@@ -289,6 +293,7 @@ def transcribe_function(stream, new_chunk):
289
 
290
 
291
 
 
292
  # Create the Gradio Blocks interface
293
  with gr.Blocks(theme="rawrsor1/Everforest") as demo:
294
  chatbot = gr.Chatbot([], elem_id="RADAR", bubble_full_width=False)
 
264
  batch_size=16,
265
  torch_dtype=torch_dtype,
266
  device=device,
267
+ return_timestamps=True,
268
+ language='en' # Ensuring transcription is done in English
269
  )
270
 
271
+
272
  def transcribe_function(stream, new_chunk):
273
  try:
274
  sr, y = new_chunk[0], new_chunk[1]
 
276
  print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
277
  return stream, "", None
278
 
279
+ y = y.astype(np.float32)
280
+ max_abs_y = np.max(np.abs(y))
281
+ if max_abs_y > 0:
282
+ y = y / max_abs_y
283
 
284
  if stream is not None:
285
  stream = np.concatenate([stream, y])
 
293
 
294
 
295
 
296
+
297
  # Create the Gradio Blocks interface
298
  with gr.Blocks(theme="rawrsor1/Everforest") as demo:
299
  chatbot = gr.Chatbot([], elem_id="RADAR", bubble_full_width=False)