As an absolute terrible front-end developer, I’ve completely fallen in love with Streamlit – it makes building apps so simple, without the hassle of handcrafting a UI from scratch π¨.
I’m currently building an app that transcribes, summarises and translates audio using the AI capabilities of OCI (more on this in a future post ποΈ).
One of the things I wanted to do in the app is record audio, thankfully Streamlit has st.audio_input, which can record audio from a users’ microphone, however I needed a way to save the recorded audio to the server running the Streamlit app so that I could work some AI-magic on it πͺ.
It turns out that this is super-simple, the code below is for a page that has the st.audio_input widget, when a recording has been created it is saved with the filename recorded_audio.wav.
import streamlit as st
st.sidebar.title("Audio Recording App")
st.title("Record Your Audio")
st.write("Press the button to start recording and then stop when you're done.")
audio = st.audio_input("Record your audio")
if audio:
with open("recorded_audio.wav", "wb") as f:
f.write(audio.getbuffer())
st.write("Audio recorded and saved successfully!")
Here’s the page in all it’s glory:

Within the directory that the Streamlit app is run from you can see that a WAV audio file has been saved:

Happy days π.

Leave a reply to arcadedark5110f6e8ec Cancel reply