helloWorld199 commited on
Commit
9f42652
1 Parent(s): 703fb58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -188,8 +188,9 @@ def add_voice_labelv2(json_file, audio_path):
188
  speech_prob = model(chunk, SAMPLING_RATE).item()
189
  speech_probs.append(speech_prob)
190
  vad_iterator.reset_states() # reset model states after each audio
191
-
192
  voice_idxs = np.where(np.array(speech_probs) >= 0.7)
 
193
  if len(voice_idxs) == 0:
194
  print("NO VOICE SEGMENTS DETECTED!")
195
  try:
@@ -202,7 +203,7 @@ def add_voice_labelv2(json_file, audio_path):
202
  begin_seq = False
203
  if voice_idxs[i+1] == voice_idxs[i]+1:
204
  continue
205
-
206
  start_time = float((start_idx*window_size_samples)/SAMPLING_RATE)
207
  end_time = float((voice_idxs[i]*window_size_samples)/SAMPLING_RATE)
208
 
@@ -210,7 +211,8 @@ def add_voice_labelv2(json_file, audio_path):
210
  end_minutes = int(end_time)
211
  start_seconds = (start_time - start_minutes) * 60
212
  end_seconds = (end_time - end_minutes) * 60
213
-
 
214
  data['vocal_times'] = {
215
  "start_time": f"{start_minutes}.{start_seconds:.2f}",
216
  "end_time": f"{end_minutes}.{end_seconds:.2f}"
@@ -224,6 +226,7 @@ def add_voice_labelv2(json_file, audio_path):
224
  print(f"An exception occurred: {e}")
225
 
226
  with open(json_file, 'w') as f:
 
227
  json.dump(data, f, indent=4)
228
 
229
  with gr.Blocks() as demo:
 
188
  speech_prob = model(chunk, SAMPLING_RATE).item()
189
  speech_probs.append(speech_prob)
190
  vad_iterator.reset_states() # reset model states after each audio
191
+
192
  voice_idxs = np.where(np.array(speech_probs) >= 0.7)
193
+ print(len(np.where(np.array(speech_probs) >= 0.7))
194
  if len(voice_idxs) == 0:
195
  print("NO VOICE SEGMENTS DETECTED!")
196
  try:
 
203
  begin_seq = False
204
  if voice_idxs[i+1] == voice_idxs[i]+1:
205
  continue
206
+
207
  start_time = float((start_idx*window_size_samples)/SAMPLING_RATE)
208
  end_time = float((voice_idxs[i]*window_size_samples)/SAMPLING_RATE)
209
 
 
211
  end_minutes = int(end_time)
212
  start_seconds = (start_time - start_minutes) * 60
213
  end_seconds = (end_time - end_minutes) * 60
214
+
215
+ print("modifying json data... \n")
216
  data['vocal_times'] = {
217
  "start_time": f"{start_minutes}.{start_seconds:.2f}",
218
  "end_time": f"{end_minutes}.{end_seconds:.2f}"
 
226
  print(f"An exception occurred: {e}")
227
 
228
  with open(json_file, 'w') as f:
229
+ print("writing_to_json...")
230
  json.dump(data, f, indent=4)
231
 
232
  with gr.Blocks() as demo: