Spaces:
Running
Running
Update
Browse files- app_gemini_voice.py +9 -6
app_gemini_voice.py
CHANGED
|
@@ -103,9 +103,9 @@ class GeminiHandler(StreamHandler):
|
|
| 103 |
self.all_output_data = audio_array
|
| 104 |
else:
|
| 105 |
self.all_output_data = np.concatenate((self.all_output_data, audio_array))
|
| 106 |
-
|
| 107 |
while self.all_output_data.shape[-1] >= self.output_frame_size:
|
| 108 |
-
yield (self.output_sample_rate,
|
| 109 |
self.all_output_data[:self.output_frame_size].reshape(1, -1))
|
| 110 |
self.all_output_data = self.all_output_data[self.output_frame_size:]
|
| 111 |
|
|
@@ -119,7 +119,7 @@ class GeminiHandler(StreamHandler):
|
|
| 119 |
try:
|
| 120 |
message = self.ws.recv(timeout=5)
|
| 121 |
msg = json.loads(message)
|
| 122 |
-
|
| 123 |
if 'serverContent' in msg:
|
| 124 |
content = msg['serverContent'].get('modelTurn', {})
|
| 125 |
yield from self._process_server_content(content)
|
|
@@ -172,14 +172,14 @@ class GeminiVoiceChat:
|
|
| 172 |
<p>Speak with Gemini using real-time audio streaming</p>
|
| 173 |
</div>
|
| 174 |
""")
|
| 175 |
-
|
| 176 |
webrtc = WebRTC(
|
| 177 |
label="Conversation",
|
| 178 |
modality="audio",
|
| 179 |
mode="send-receive",
|
| 180 |
rtc_configuration=get_twilio_turn_credentials()
|
| 181 |
)
|
| 182 |
-
|
| 183 |
webrtc.stream(
|
| 184 |
GeminiHandler(),
|
| 185 |
inputs=[webrtc],
|
|
@@ -197,4 +197,7 @@ def demo():
|
|
| 197 |
return chat.demo
|
| 198 |
|
| 199 |
# This is what will be imported by app.py
|
| 200 |
-
demo = demo()
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
self.all_output_data = audio_array
|
| 104 |
else:
|
| 105 |
self.all_output_data = np.concatenate((self.all_output_data, audio_array))
|
| 106 |
+
|
| 107 |
while self.all_output_data.shape[-1] >= self.output_frame_size:
|
| 108 |
+
yield (self.output_sample_rate,
|
| 109 |
self.all_output_data[:self.output_frame_size].reshape(1, -1))
|
| 110 |
self.all_output_data = self.all_output_data[self.output_frame_size:]
|
| 111 |
|
|
|
|
| 119 |
try:
|
| 120 |
message = self.ws.recv(timeout=5)
|
| 121 |
msg = json.loads(message)
|
| 122 |
+
|
| 123 |
if 'serverContent' in msg:
|
| 124 |
content = msg['serverContent'].get('modelTurn', {})
|
| 125 |
yield from self._process_server_content(content)
|
|
|
|
| 172 |
<p>Speak with Gemini using real-time audio streaming</p>
|
| 173 |
</div>
|
| 174 |
""")
|
| 175 |
+
|
| 176 |
webrtc = WebRTC(
|
| 177 |
label="Conversation",
|
| 178 |
modality="audio",
|
| 179 |
mode="send-receive",
|
| 180 |
rtc_configuration=get_twilio_turn_credentials()
|
| 181 |
)
|
| 182 |
+
|
| 183 |
webrtc.stream(
|
| 184 |
GeminiHandler(),
|
| 185 |
inputs=[webrtc],
|
|
|
|
| 197 |
return chat.demo
|
| 198 |
|
| 199 |
# This is what will be imported by app.py
|
| 200 |
+
demo = demo()
|
| 201 |
+
|
| 202 |
+
if __name__ == "__main__":
|
| 203 |
+
demo.launch(server_name="0.0.0.0")
|