Summary
How do I create audio player from uploaded .wav file, which asyncronously streams every 1024 packet to servers and print stt response to web, when client clicks play button?
My approach is as below. I could create audio player via audio_tag, but I got stuck at triggering callback funciton and handle response
import base64
import streamlit as st
import requests
def get_audio_file_content(audio_file,callback_function:str):
audio_bytes = audio_file.read()
encoded_bytes = base64.b64encode(audio_bytes).decode('utf-8')
audio_tag = f'<audio controls src="data:audio/wav;base64,{encoded_bytes}" onclick=f"{callback_function}"></audio>'
return audio_tag
def main():
st.title("Audio Player")
# Upload audio file
uploaded_file = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
callback_function = """
<script>
</script>
"""
if uploaded_file is not None:
audio_tag = get_audio_file_content(uploaded_file,callback_function)
st.markdown(audio_tag, unsafe_allow_html=True)
if __name__ == "__main__":
main()