This guide demonstrates how to set up a Streamlit app to transcribe MP3 audio files using AssemblyAI. You’ll learn how to set up your environment, configure your API key, and create a simple app to transcribe audio from a given URL.
transcribe-mp3-streamlit-snippet.mdx
import streamlit as stimport assemblyai as aaiimport osfrom dotenv import load_dotenv# Load environment variables from .env fileload_dotenv()# Get API key from environment variablesASSEMBLYAI_API_KEY = os.getenv('ASSEMBLYAI_API_KEY')aai.settings.api_key = ASSEMBLYAI_API_KEYdeftranscribe_audio(audio_url):# Create a Transcriber object transcriber = aai.Transcriber()# Transcribe the audio file from the URL transcript = transcriber.transcribe(audio_url) paragraphs = transcript.get_paragraphs()return paragraphsst.title('MP3 Transcription using AssemblyAI')# MP3 URL Inputmp3_url = st.text_input('Enter MP3 URL')if st.button('Transcribe'):ifnot mp3_url: st.error('Please enter a valid MP3 URL.')else:with st.spinner('Transcribing...'):# Transcribe the audio file using the URL paragraphs = transcribe_audio(mp3_url)for paragraph in paragraphs: st.write(paragraph.text)
Create a Python script named main.py with the following content:
transcribe-mp3-streamlit-snippet.mdx
import streamlit as stimport assemblyai as aaiimport osfrom dotenv import load_dotenv# Load environment variables from .env fileload_dotenv()# Get API key from environment variablesASSEMBLYAI_API_KEY = os.getenv('ASSEMBLYAI_API_KEY')aai.settings.api_key = ASSEMBLYAI_API_KEYdeftranscribe_audio(audio_url):# Create a Transcriber object transcriber = aai.Transcriber()# Transcribe the audio file from the URL transcript = transcriber.transcribe(audio_url) paragraphs = transcript.get_paragraphs()return paragraphsst.title('MP3 Transcription using AssemblyAI')# MP3 URL Inputmp3_url = st.text_input('Enter MP3 URL')if st.button('Transcribe'):ifnot mp3_url: st.error('Please enter a valid MP3 URL.')else:with st.spinner('Transcribing...'):# Transcribe the audio file using the URL paragraphs = transcribe_audio(mp3_url)for paragraph in paragraphs: st.write(paragraph.text)
You have successfully set up a Streamlit app to transcribe MP3 audio files using AssemblyAI! This guide provided a basic example to get you started. You can now expand on this by customizing the transcription process and enhancing the app’s functionality.