import streamlit as st import datetime import os # Initialize session state for transcript history if not exists if 'transcript_history' not in st.session_state: st.session_state.transcript_history = "" # Create a container for the transcript history history_container = st.empty() text_area = st.empty() html = """ Continuous Speech Demo

Continuous Speech Recognition

Ready
""" # Create custom component def speech_recognition(): component_value = st.components.v1.html(html, height=600) return component_value # Function to save transcript to file def save_transcript(text): if not os.path.exists('transcripts'): os.makedirs('transcripts') timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S') filename = f"transcripts/transcript_{timestamp}.md" with open(filename, 'a', encoding='utf-8') as f: f.write(text + '\n') # Main app st.title("Speech Recognition with Transcript History") # Get the speech recognition component value result = speech_recognition() # If we receive a new transcript if result: transcript_data = result # Update the transcript history if transcript_data.get('isFinal', False): new_text = transcript_data.get('text', '') st.session_state.transcript_history += new_text # Save to file save_transcript(new_text) # Update the display history_container.markdown(st.session_state.transcript_history) text_area.text_area("Full Transcript", st.session_state.transcript_history, height=200) # Add a download button for the full transcript if st.session_state.transcript_history: st.download_button( label="Download Full Transcript", data=st.session_state.transcript_history, file_name=f"transcript_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.md", mime="text/markdown" )