Spaces:
Sleeping
Sleeping
Commit
·
4562675
1
Parent(s):
8df75a7
Check point 4
Browse files
app.py
CHANGED
@@ -651,8 +651,7 @@ def start_recording():
|
|
651 |
"""Start recording and transcription"""
|
652 |
try:
|
653 |
result = diarization_system.start_recording()
|
654 |
-
#
|
655 |
-
audio_webrtc.stream_url = "/stream" # This is your FastRTC endpoint
|
656 |
return result
|
657 |
except Exception as e:
|
658 |
return f"❌ Failed to start recording: {str(e)}"
|
@@ -706,7 +705,7 @@ def create_interface():
|
|
706 |
# Add WebRTC component for audio streaming
|
707 |
audio_webrtc = WebRTC(
|
708 |
label="Audio Input",
|
709 |
-
|
710 |
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]}
|
711 |
)
|
712 |
|
@@ -783,8 +782,7 @@ def create_interface():
|
|
783 |
|
784 |
def on_start():
|
785 |
result = start_recording()
|
786 |
-
#
|
787 |
-
audio_webrtc.stream_url = "/stream" # This is your FastRTC endpoint
|
788 |
return result, gr.update(interactive=False), gr.update(interactive=True)
|
789 |
|
790 |
def on_stop():
|
@@ -840,19 +838,17 @@ def create_interface():
|
|
840 |
status_timer = gr.Timer(2)
|
841 |
status_timer.tick(refresh_status, outputs=[status_output])
|
842 |
|
843 |
-
# After creating the WebRTC component:
|
844 |
-
audio_webrtc.stream(
|
845 |
-
fn=process_webrtc_audio,
|
846 |
-
inputs=[audio_webrtc],
|
847 |
-
outputs=[conversation_output]
|
848 |
-
)
|
849 |
-
|
850 |
return interface
|
851 |
|
852 |
|
853 |
# FastAPI setup for FastRTC integration
|
854 |
app = FastAPI()
|
855 |
|
|
|
|
|
|
|
|
|
|
|
856 |
@app.get("/")
|
857 |
async def root():
|
858 |
return {"message": "Real-time Speaker Diarization API"}
|
@@ -894,12 +890,6 @@ async def api_update_settings(threshold: float, max_speakers: int):
|
|
894 |
result = update_settings(threshold, max_speakers)
|
895 |
return {"result": result}
|
896 |
|
897 |
-
# FastRTC Stream setup
|
898 |
-
if audio_handler:
|
899 |
-
stream = Stream(handler=audio_handler)
|
900 |
-
app.include_router(stream.router, prefix="/stream")
|
901 |
-
|
902 |
-
|
903 |
# Main execution
|
904 |
if __name__ == "__main__":
|
905 |
import argparse
|
@@ -959,10 +949,4 @@ if __name__ == "__main__":
|
|
959 |
api_thread.start()
|
960 |
|
961 |
# Start Gradio in main thread
|
962 |
-
run_gradio()
|
963 |
-
|
964 |
-
def process_webrtc_audio(frames):
|
965 |
-
# Process frames and send them to your diarization system
|
966 |
-
for frame in frames:
|
967 |
-
diarization_system.process_audio_chunk(frame)
|
968 |
-
return get_conversation()
|
|
|
651 |
"""Start recording and transcription"""
|
652 |
try:
|
653 |
result = diarization_system.start_recording()
|
654 |
+
# FastRTC connection is handled through the mounted stream
|
|
|
655 |
return result
|
656 |
except Exception as e:
|
657 |
return f"❌ Failed to start recording: {str(e)}"
|
|
|
705 |
# Add WebRTC component for audio streaming
|
706 |
audio_webrtc = WebRTC(
|
707 |
label="Audio Input",
|
708 |
+
source_url="/stream", # Connect to the FastRTC stream endpoint
|
709 |
rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]}
|
710 |
)
|
711 |
|
|
|
782 |
|
783 |
def on_start():
|
784 |
result = start_recording()
|
785 |
+
# FastRTC connection is handled through the mounted stream
|
|
|
786 |
return result, gr.update(interactive=False), gr.update(interactive=True)
|
787 |
|
788 |
def on_stop():
|
|
|
838 |
status_timer = gr.Timer(2)
|
839 |
status_timer.tick(refresh_status, outputs=[status_output])
|
840 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
841 |
return interface
|
842 |
|
843 |
|
844 |
# FastAPI setup for FastRTC integration
|
845 |
app = FastAPI()
|
846 |
|
847 |
+
# Initialize audio handler for FastRTC
|
848 |
+
audio_handler = DiarizationHandler(diarization_system)
|
849 |
+
stream = Stream(handler=audio_handler, modality="audio", mode="send-receive")
|
850 |
+
stream.mount(app) # Mount the Stream to the FastAPI app
|
851 |
+
|
852 |
@app.get("/")
|
853 |
async def root():
|
854 |
return {"message": "Real-time Speaker Diarization API"}
|
|
|
890 |
result = update_settings(threshold, max_speakers)
|
891 |
return {"result": result}
|
892 |
|
|
|
|
|
|
|
|
|
|
|
|
|
893 |
# Main execution
|
894 |
if __name__ == "__main__":
|
895 |
import argparse
|
|
|
949 |
api_thread.start()
|
950 |
|
951 |
# Start Gradio in main thread
|
952 |
+
run_gradio()
|
|
|
|
|
|
|
|
|
|
|
|