majweldon commited on
Commit
e4fddaa
·
verified ·
1 Parent(s): feb1d27

Update app.py

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