import streamlit as st import datetime import os import json # 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
""" # 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") # Create custom component and get its value component_value = st.components.v1.html(html, height=600) # If we receive a new transcript if component_value: # The component_value will be the direct transcript text new_text = str(component_value) # Only process non-empty transcripts if new_text.strip(): # Update the transcript history 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" )