Commit
•
63b59c5
1
Parent(s):
d9f5363
Modifications
Browse files
app.py
CHANGED
@@ -89,7 +89,8 @@ class AppState:
|
|
89 |
stream: np.ndarray | None = None
|
90 |
sampling_rate: int = 0
|
91 |
pause_detected: bool = False
|
92 |
-
started_talking =
|
|
|
93 |
|
94 |
|
95 |
def determine_pause(audio: np.ndarray, sampling_rate: int, state: AppState) -> bool:
|
@@ -171,7 +172,7 @@ def process_audio(audio: tuple, state: AppState):
|
|
171 |
|
172 |
|
173 |
def response(state: AppState):
|
174 |
-
if not state.pause_detected:
|
175 |
return None, AppState()
|
176 |
|
177 |
for mp3_bytes in speaking(state.stream, state.sampling_rate):
|
@@ -181,9 +182,8 @@ def response(state: AppState):
|
|
181 |
|
182 |
|
183 |
def start_recording_user(state: AppState):
|
184 |
-
if
|
185 |
return gr.Audio(recording=True)
|
186 |
-
return None
|
187 |
|
188 |
with gr.Blocks() as demo:
|
189 |
with gr.Row():
|
@@ -213,7 +213,7 @@ with gr.Blocks() as demo:
|
|
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()
|
|
|
89 |
stream: np.ndarray | None = None
|
90 |
sampling_rate: int = 0
|
91 |
pause_detected: bool = False
|
92 |
+
started_talking: bool = False
|
93 |
+
stopped: bool = False
|
94 |
|
95 |
|
96 |
def determine_pause(audio: np.ndarray, sampling_rate: int, state: AppState) -> bool:
|
|
|
172 |
|
173 |
|
174 |
def response(state: AppState):
|
175 |
+
if not state.pause_detected and not state.started_talking:
|
176 |
return None, AppState()
|
177 |
|
178 |
for mp3_bytes in speaking(state.stream, state.sampling_rate):
|
|
|
182 |
|
183 |
|
184 |
def start_recording_user(state: AppState):
|
185 |
+
if not state.stopped:
|
186 |
return gr.Audio(recording=True)
|
|
|
187 |
|
188 |
with gr.Blocks() as demo:
|
189 |
with gr.Row():
|
|
|
213 |
[input_audio]
|
214 |
)
|
215 |
cancel = gr.Button("Stop Conversation", variant="stop")
|
216 |
+
cancel.click(lambda: (AppState(stopped=True), gr.Audio(recording=False)), None, [state, input_audio], cancels=[respond, restart])
|
217 |
|
218 |
|
219 |
demo.launch()
|