Spaces:
Running
on
T4
Running
on
T4
Commit
•
d9f5363
1
Parent(s):
5f58cac
Add code
Browse files
app.py
CHANGED
@@ -107,7 +107,7 @@ def determine_pause(audio: np.ndarray, sampling_rate: int, state: AppState) -> b
|
|
107 |
|
108 |
print(f"duration_after_vad: {dur_vad:.3f} s, time_vad: {time_vad:.3f} s")
|
109 |
|
110 |
-
return (duration - dur_vad) >
|
111 |
|
112 |
|
113 |
def speaking(audio: np.ndarray, sampling_rate: int):
|
@@ -180,6 +180,11 @@ def response(state: AppState):
|
|
180 |
yield None, AppState()
|
181 |
|
182 |
|
|
|
|
|
|
|
|
|
|
|
183 |
with gr.Blocks() as demo:
|
184 |
with gr.Row():
|
185 |
with gr.Column():
|
@@ -202,13 +207,13 @@ with gr.Blocks() as demo:
|
|
202 |
[state],
|
203 |
[output_audio, state]
|
204 |
)
|
205 |
-
output_audio.stop(
|
206 |
-
|
207 |
-
|
208 |
[input_audio]
|
209 |
)
|
210 |
cancel = gr.Button("Stop Conversation", variant="stop")
|
211 |
-
cancel.click(lambda: AppState(), None, [state], cancels=[respond])
|
212 |
|
213 |
|
214 |
demo.launch()
|
|
|
107 |
|
108 |
print(f"duration_after_vad: {dur_vad:.3f} s, time_vad: {time_vad:.3f} s")
|
109 |
|
110 |
+
return (duration - dur_vad) > 1
|
111 |
|
112 |
|
113 |
def speaking(audio: np.ndarray, sampling_rate: int):
|
|
|
180 |
yield None, AppState()
|
181 |
|
182 |
|
183 |
+
def start_recording_user(state: AppState):
|
184 |
+
if state.pause_detected and state.started_talking:
|
185 |
+
return gr.Audio(recording=True)
|
186 |
+
return None
|
187 |
+
|
188 |
with gr.Blocks() as demo:
|
189 |
with gr.Row():
|
190 |
with gr.Column():
|
|
|
207 |
[state],
|
208 |
[output_audio, state]
|
209 |
)
|
210 |
+
restart = output_audio.stop(
|
211 |
+
start_recording_user,
|
212 |
+
[state],
|
213 |
[input_audio]
|
214 |
)
|
215 |
cancel = gr.Button("Stop Conversation", variant="stop")
|
216 |
+
cancel.click(lambda: AppState(), None, [state], cancels=[respond, restart])
|
217 |
|
218 |
|
219 |
demo.launch()
|