Hello,
I am trying to display the audio file that I upload and it fails with the following error"
TypeError: ‘bytes’ object is not callable
Here is what I have so far:
fileObject = st.file_uploader(
label="Please upload your audio file", type=["mp3"])
if fileObject is not None:
st.write(type(fileObject))
file_details = {"filename": fileObject.name,
"filetype": fileObject.type, "filesize": fileObject.size}
st.write(file_details)
audio_bytes = fileObject.getvalue()
st.audio(audio_bytes, format='audio/mp3')
token, t_id = upload_file(fileObject)
result = {}
Basically, I want to display the audio file player so that I can click on it to play the audio file after I have uploaded the file.
I can upload the file but the audio player does not show.
Thanks
Hi @dariushazimi, would you mind sharing the entire error message so we can help debug? The message should point to the line of code causing the error.
When I run your code, I’m able to upload an audio file, see the audio player, and click on it to play the audio file. The only error I see is related to upload_file()
, which isn’t defined in your code snippet:
import streamlit as st
fileObject = st.file_uploader(
label="Please upload your audio file", type=["mp3"])
if fileObject is not None:
st.write(type(fileObject))
file_details = {"filename": fileObject.name,
"filetype": fileObject.type, "filesize": fileObject.size}
st.write(file_details)
audio_bytes = fileObject.getvalue()
st.audio(audio_bytes, format='audio/mp3')
token, t_id = upload_file(fileObject) # undefined
result = {}
Best,
Snehan
1 Like
Thank you Snehan, I retried the code again and restarted the server and it is now working fine. Thanks for looking at this.
2 Likes