freddyaboulton HF staff commited on
Commit
556b4ae
1 Parent(s): 41d06ba
Files changed (1) hide show
  1. app.py +21 -28
app.py CHANGED
@@ -78,34 +78,27 @@ def warm_up():
78
 
79
  warm_up()
80
 
81
- def determine_pause():
82
- temp_audio = b""
83
- vad_audio = b""
84
-
85
- start_talking = False
86
- last_temp_audio = None
87
-
88
- while st.session_state.recording:
89
- status.success("Listening...")
90
- audio_bytes = stream.read(IN_CHUNK)
91
- temp_audio += audio_bytes
92
-
93
- if len(temp_audio) > IN_SAMPLE_WIDTH * IN_RATE * IN_CHANNELS * VAD_STRIDE:
94
- dur_vad, vad_audio_bytes, time_vad = run_vad(temp_audio, IN_RATE)
95
-
96
- print(f"duration_after_vad: {dur_vad:.3f} s, time_vad: {time_vad:.3f} s")
97
-
98
- if dur_vad > 0.2 and not start_talking:
99
- if last_temp_audio is not None:
100
- st.session_state.frames.append(last_temp_audio)
101
- start_talking = True
102
- if start_talking:
103
- st.session_state.frames.append(temp_audio)
104
- if dur_vad < 0.1 and start_talking:
105
- st.session_state.recording = False
106
- print(f"speech end detected. excit")
107
- last_temp_audio = temp_audio
108
- temp_audio = b""
109
 
110
 
111
  def process_audio(audio):
 
78
 
79
  warm_up()
80
 
81
+ def determine_pause(stream: bytes, start_talking: bool) -> tuple[bytes, bool]:
82
+ """Take in the stream, determine if a pause happened"""
83
+
84
+ temp_audio = stream
85
+
86
+ if len(temp_audio) > IN_SAMPLE_WIDTH * IN_RATE * IN_CHANNELS * VAD_STRIDE:
87
+ dur_vad, vad_audio_bytes, time_vad = run_vad(temp_audio, IN_RATE)
88
+
89
+ print(f"duration_after_vad: {dur_vad:.3f} s, time_vad: {time_vad:.3f} s")
90
+
91
+ if dur_vad > 0.2 and not start_talking:
92
+ if last_temp_audio is not None:
93
+ st.session_state.frames.append(last_temp_audio)
94
+ start_talking = True
95
+ if start_talking:
96
+ st.session_state.frames.append(temp_audio)
97
+ if dur_vad < 0.1 and start_talking:
98
+ st.session_state.recording = False
99
+ print(f"speech end detected. excit")
100
+ last_temp_audio = temp_audio
101
+ temp_audio = b""
 
 
 
 
 
 
 
102
 
103
 
104
  def process_audio(audio):