SYNRG / src /ui /pages /call_recorder.py
cryogenic22's picture
Update src/ui/pages/call_recorder.py
2abd910 verified
"""
Enhanced call recorder page with proper state management
"""
import streamlit as st
from audio_recorder_streamlit import audio_recorder
from datetime import datetime
import uuid
def show():
"""Display call recorder page"""
st.title("πŸ“ž Call Recorder & Analysis")
# Initialize services
transcription_service = st.session_state.services['transcription']
llm_service = st.session_state.services['llm']
# Initialize session state
if 'audio_bytes' not in st.session_state:
st.session_state.audio_bytes = None
# Recording section
st.markdown("### πŸŽ™οΈ Recording")
col1, col2, col3 = st.columns([1, 2, 1])
with col2:
audio_bytes = audio_recorder(
pause_threshold=60.0,
sample_rate=44100,
text="",
recording_color="#e74c3c",
neutral_color="#3498db",
icon_size="6x"
)
if audio_bytes:
st.session_state.audio_bytes = audio_bytes
# Process recording if we have audio
if st.session_state.audio_bytes:
# Display audio player
st.audio(st.session_state.audio_bytes, format="audio/wav")
# Process if not already processed
if not st.session_state.get('is_processing', False) and not st.session_state.get('last_transcription'):
try:
result = transcription_service.process_audio(
st.session_state.audio_bytes,
llm_service
)
if result:
st.markdown("### πŸ“ Transcript")
st.text_area(
"Transcript",
value=result['transcript'],
height=200,
key="transcript"
)
if 'analysis' in result:
st.markdown("### 🎯 Analysis")
st.json(result['analysis'])
except Exception as e:
st.error(f"Error processing recording: {str(e)}")
# Clear recording button
if st.session_state.get('audio_bytes') is not None:
if st.button("πŸ”„ Clear Recording"):
transcription_service.clear_recording()
if __name__ == "__main__":
show()