I want that, in my website, when I click on a timecode (e.g: 1.26), it recall the audio player at this start time and play the audio.
Steps to reproduce
Here is the parse of my code of the current audio playing solution:
strmlt.subheader("Audio file")
audio=strmlt.file_uploader("Download an audio file (format wav)",type="wav")
#getting the audio file
if(audio is not None):
strmlt.subheader("Transcription")
audio_file=audio.read()
#readable audio
strmlt.caption("Listen to the call")
strmlt.audio(audio_file,format='audio/wav', start_time=60)
#audio player
@dataprofessor Hi, indeed, I’ve already saw this, the problem is that I don’t know how to change dynamically the states of the player (from starting to 1min, to starting at 20s for example, by clicking on a text)
Perhaps you can experiment with the above so that clicking on a link would take us to the specific segment of the audio (using the above query parameters with start_time parameter).
@dataprofessor I don’t really know how to implement this on the hyperlink provided by the time code click (highlighted in blue), with the start_time and the query experimental feature
Hi @Goyo , indeed, that’s because I don’t have implemented this yet, because I don’t know how to do.
I said Hyperlink cause in french it’s called “hyperlien”, sorry. By this name I mean the link you click and allow you to refresh one element of the website, here the audio player. For example, by clicking on the time code 00:02:800 it will play the audio on the upper player at 2,8s.
You could use an input widget to allow the user to select when to start playing, like this:
import streamlit as st
st.subheader("Audio file")
audio = st.file_uploader("Download an audio file (format wav)", type="wav")
# getting the audio file
if audio is not None:
st.subheader("Transcription")
audio_file = audio.read()
# readable audio
# st.caption("Listen to the call")
if st.button("Play from start"):
st.audio(audio_file, format="audio/wav")
if st.button("Play from 10 seconds"):
st.audio(audio_file, format="audio/wav", start_time=10)
if st.button("Play from 20 seconds"):
st.audio(audio_file, format="audio/wav", start_time=20)
Oh thank you @blackary . Unfortunately, it’s not really what i’m serching for. Indeed, my goal is to enable a link on the text that refresh the player at the selected timecode.
What about styling buttons to look like links, like this?
import streamlit as st
from streamlit_extras.stylable_container import stylable_container
st.subheader("Audio file")
audio = st.file_uploader("Download an audio file (format wav)", type="wav")
if "start_time" not in st.session_state:
st.session_state.start_time = 0
# Style buttons as links
with stylable_container(
key="link_buttons",
css_styles="""
button {
background: none!important;
border: none;
padding: 0!important;
font-family: arial, sans-serif;
color: #069;
text-decoration: underline;
cursor: pointer;
}
""",
):
# getting the audio file
if audio is not None:
st.subheader("Transcription")
audio_file = audio.read()
for time in range(0, 60, 10):
start = time
end = time + 10
range = f"00:{start:02} - 00:{end}"
if st.button(range):
st.session_state["start_time"] = start
st.experimental_rerun()
st.audio(audio_file, format="audio/wav", start_time=st.session_state.start_time)
split each line into two columns, e.g.: timestamp | content
create a dataframe to use with st.table(df) with proper styling.
Assuming the table is responsive, write a row_clicked callback, e.g. on row_clicked, retrieve the index, parse the 1st portion of the timestamp, convert to seconds → new start time.
Hope this helps!
UPDATE
I tried providing an example of my proposed implementation, but I was assuming too much about streamlit.
Streamlit’s “elements” are not (all) widgets. I was assuming that st.dataframe or st.edit_data would have an on_click property (st.edit_data can have a callback but only for the “on change” event!).
I am confused: In the screenshot of your original post, the timestamps look like
00:00.800 --> 00:01.800 ...
Since they come from a text file, they need to be parsed and converted to decimal seconds to be useable by the audio widget. Now, with your new “raw texts”, it seems you have already converted them (yet they are still not useable as is).
Which is the real raw format?
PS: The proposal from @backary seem viable. Have you tried it? Please let the community knows, thank you.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.