majweldon commited on
Commit
2ab8097
·
verified ·
1 Parent(s): aae8a6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -47,27 +47,27 @@ def transcribe(audio, history_type):
47
 
48
 
49
  ######################## Take Audio from Numpy Array
50
- samplerate, audio_data = audio
51
 
52
 
53
  ######################## Read audio file, if using file
54
- #max_attempts = 1
55
- #attempt = 0
56
- #audio_data = None
57
- #samplerate = None
58
- #while attempt < max_attempts:
59
- # try:
60
- # if audio is None:
61
- # raise TypeError("Invalid file: None")
62
- # audio_data, samplerate = sf.read(audio)
63
- # break
64
- # except (OSError, TypeError) as e:
65
- # print(f"Attempt {attempt + 1} of {max_attempts} failed with error: {e}")
66
- # attempt += 1
67
- # time.sleep(3)
68
- #else:
69
- # print(f"###############Failed to open audio file after {max_attempts} attempts.##############")
70
- # return # Terminate the function or raise an exception if the file could not be opened
71
 
72
 
73
  ########## Cast as float 32, normalize
 
47
 
48
 
49
  ######################## Take Audio from Numpy Array
50
+ #samplerate, audio_data = audio
51
 
52
 
53
  ######################## Read audio file, if using file
54
+ max_attempts = 1
55
+ attempt = 0
56
+ audio_data = None
57
+ samplerate = None
58
+ while attempt < max_attempts:
59
+ try:
60
+ if audio is None:
61
+ raise TypeError("Invalid file: None")
62
+ audio_data, samplerate = sf.read(audio)
63
+ break
64
+ except (OSError, TypeError) as e:
65
+ print(f"Attempt {attempt + 1} of {max_attempts} failed with error: {e}")
66
+ attempt += 1
67
+ time.sleep(3)
68
+ else:
69
+ print(f"###############Failed to open audio file after {max_attempts} attempts.##############")
70
+ return # Terminate the function or raise an exception if the file could not be opened
71
 
72
 
73
  ########## Cast as float 32, normalize