I've made a voice chatting app using streamlit. I want to make the start recording…
- User
I've made a voice chatting app using streamlit. I want to make the start recording button to be automatically pressed(id='record') after the audio is finished import os os.environ['KMP_DUPLICATE_LIB_OK']='True'
import streamlit as st from st_audiorec import st_audiorec from voice import text_to_speech from gen_response import generate from faster_whisper import WhisperModel import io from datetime import datetime import base64 from streamlit_cookies_controller import CookieController import random import string from streamlit_js_eval import streamlit_js_eval
controller = CookieController()
try: st.set_page_config(page_title='Julia') except: pass
st.title('Julia') st.divider()
Initialize Whisper model (make sure you have the Whisper library installed)
model_size = "tiny.en" model = WhisperModel(model_size, device="cuda", compute_type="int8")
def transcribe_audio(wav_audio_data): # Convert the byte data to a NumPy array and write it to a WAV file-like object wav_file = io.BytesIO(wav_audio_data)
code# Transcribe the audio data without specifying sample rate segments, _ = model.transcribe(wav_file, beam_size=5) # Concatenate the text from all segments transcribed_text = " ".join([segment.text for segment in segments]) # Output the transcribed text return transcribed_textdef autoplay_audio(file_path: str): with open(file_path, "rb") as f: data = f.read() b64 = base64.b64encode(data).decode() md = f""" """ st.markdown( md, unsafe_allow_html=True, )
name = st.text_input('Enter your name') model_size = st.selectbox( "Select the STT model size.", ("large-v3", "medium", "small", "base", 'tiny'), index=0 ) now = datetime.now()
if controller.get('sessionid') == None: controller.set('sessionid', ''.join(random.choices(string.ascii_uppercase + string.digits, k=10)))
if name: if 'messages' not in st.session_state: st.session_state.messages = [{'role':'system', 'content':f'You are Julia, a cute and humorous Christian girl. You are a girlfriend of user and flirt user to make him feel better. User's name is {name}. Current time is {now.year}-{now.month}-{now.day} {now.hour}:{now.minute}. But remember to answer shortly in a sentence.'}]
code - Assistant