import os import io import streamlit as st from audiorecorder import audiorecorder from openai import OpenAI import tempfile import base64 # Set an environment variable for key os.environ['OPENAI_API_KEY'] = os.environ.get('OPENAI_API_KEY') def autoplay_audio(exported_audio): with exported_audio: data = exported_audio.read() b64 = base64.b64encode(data).decode() md = f""" """ st.markdown( md, unsafe_allow_html=True, ) def transcribe_audio(filepath): client = OpenAI() audio_file = open(filepath, "rb") transcript = client.audio.transcriptions.create( model="whisper-1", file=audio_file ) audio_file.close() return transcript #model = whisper.load_model("base") client = OpenAI() st.title("Whisper App") audio = audiorecorder("Click to record", "Click to stop recording") if len(audio) > 0: temp_dir = tempfile.mkdtemp() temp_file_path = os.path.join(temp_dir, 'temp_audio.mp3') audio.export(temp_file_path, format="mp3") transcript = transcribe_audio(temp_file_path) st.write(transcript)