D3V1L1810 commited on
Commit
d35432e
·
verified ·
1 Parent(s): 1cf2ba3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -41,7 +41,7 @@ def convert_mp3_to_wav(mp3_data):
41
  wav_buffer.seek(0)
42
  return wav_buffer.getvalue()
43
 
44
- def process_audio_file(file_data, url):
45
  try:
46
  sample_rate, wav_data = wavfile.read(BytesIO(file_data))
47
  if wav_data.ndim > 1:
@@ -62,7 +62,7 @@ def process_audio_file(file_data, url):
62
  if inferred_class == "Silence" and len(top_two_indices) > 1:
63
  inferred_class = class_names[top_two_indices[1]]
64
 
65
- answer_dict = {'url': url, 'answer': [inferred_class]}
66
  return answer_dict
67
  except Exception as e:
68
  logging.error(f"Error processing {url}: {e}")
@@ -96,19 +96,20 @@ def process_audio(params):
96
  return {"error": f"Invalid JSON input: {e.msg} at line {e.lineno} column {e.colno}"}
97
 
98
  audio_files = params.get("urls", [])
 
99
  # api = params.get("api", "")
100
  # job_id = params.get("job_id", "")
101
 
102
  solutions = []
103
- for audio_url in audio_files:
104
  audio_data = get_audio_data(audio_url)
105
 
106
  if audio_url.endswith(".mp3"):
107
  wav_data = convert_mp3_to_wav(audio_data)
108
- result = process_audio_file(wav_data, audio_url)
109
 
110
  elif audio_url.endswith(".wav"):
111
- result = process_audio_file(audio_data, audio_url)
112
 
113
  if result:
114
  solutions.append(result)
 
41
  wav_buffer.seek(0)
42
  return wav_buffer.getvalue()
43
 
44
+ def process_audio_file(file_data, url, file_id):
45
  try:
46
  sample_rate, wav_data = wavfile.read(BytesIO(file_data))
47
  if wav_data.ndim > 1:
 
62
  if inferred_class == "Silence" and len(top_two_indices) > 1:
63
  inferred_class = class_names[top_two_indices[1]]
64
 
65
+ answer_dict = {'url': url, 'answer': [inferred_class], qcUser: None, "normalfileID": file_id}
66
  return answer_dict
67
  except Exception as e:
68
  logging.error(f"Error processing {url}: {e}")
 
96
  return {"error": f"Invalid JSON input: {e.msg} at line {e.lineno} column {e.colno}"}
97
 
98
  audio_files = params.get("urls", [])
99
+ file_ids = params.get("normalfileID", [])
100
  # api = params.get("api", "")
101
  # job_id = params.get("job_id", "")
102
 
103
  solutions = []
104
+ for audio_url,file_id in zip(audio_files, file_ids):
105
  audio_data = get_audio_data(audio_url)
106
 
107
  if audio_url.endswith(".mp3"):
108
  wav_data = convert_mp3_to_wav(audio_data)
109
+ result = process_audio_file(wav_data, audio_url, file_id)
110
 
111
  elif audio_url.endswith(".wav"):
112
+ result = process_audio_file(audio_data, audio_url, file_id)
113
 
114
  if result:
115
  solutions.append(result)