Baghdad99 commited on
Commit
404d7f0
1 Parent(s): 32b7f55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -1
app.py CHANGED
@@ -3,7 +3,6 @@ import requests
3
  import soundfile as sf
4
  import numpy as np
5
  import tempfile
6
- #lets work it out
7
 
8
  # Define the Hugging Face Inference API URLs and headers
9
  ASR_API_URL = "https://api-inference.huggingface.co/models/Baghdad99/saad-speech-recognition-hausa-audio-to-text"
@@ -20,6 +19,8 @@ def query(api_url, payload):
20
  def translate_speech(audio):
21
  # audio is a tuple (np.ndarray, int), we need to save it as a file
22
  audio_data, sample_rate = audio
 
 
23
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
24
  sf.write(f, audio_data, sample_rate)
25
  audio_file = f.name
 
3
  import soundfile as sf
4
  import numpy as np
5
  import tempfile
 
6
 
7
  # Define the Hugging Face Inference API URLs and headers
8
  ASR_API_URL = "https://api-inference.huggingface.co/models/Baghdad99/saad-speech-recognition-hausa-audio-to-text"
 
19
  def translate_speech(audio):
20
  # audio is a tuple (np.ndarray, int), we need to save it as a file
21
  audio_data, sample_rate = audio
22
+ if len(audio_data.shape) == 1: # if audio_data is 1D, reshape it to 2D
23
+ audio_data = np.reshape(audio_data, (-1, 1))
24
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
25
  sf.write(f, audio_data, sample_rate)
26
  audio_file = f.name