I am uploading several audio recording files every day into my test app. (bird sounds)
Not all recorders include the time of the recording in the name.
This is useful because bird activities depend on time!
Therefore, I hoped to retrieve the “modified datetime” of the files for this purpose.
Unfortunately, I was not able to do that.
And I guess the file metadata are probably not included in the upload.
Are these metadata, especially the “modified date” completely out of reach within streamlit?
Or would they be available somehow / somewhere?
Thanks for posting! Streamlit itself does not have a feature to extract the timestamps but you can find workarounds using Python to preprocess the audio files before uploading them. You can basically run all your audio files through this script as part of your pipeline to make sure they’re all timestamped correctly.
You can use the Mutagen module to handle the audio metadata before uploading them. Here’s example code to get you started:
import os
import mutagen
from mutagen.mp3 import MP3
import time
import streamlit as st
# Folder containing audio files
audio_dir = 'path/to/audio/files'
for filename in os.listdir(audio_dir):
if filename.endswith('.mp3'):
# Open audio file with Mutagen
audio = MP3(os.path.join(audio_dir, filename))
# Extract metadata
mod_time = os.path.getmtime(os.path.join(audio_dir, filename))
mod_time_str = time.strftime('%Y-%m-%d_%H-%M-%S', time.localtime(mod_time))
# Construct new file name
name, ext = os.path.splitext(filename)
new_name = f'{name}_{mod_time_str}{ext}'
# Rename file
new_path = os.path.join(audio_dir, new_name)
os.rename(os.path.join(audio_dir, filename), new_path)
Thanks for the suggestions.
I always use wav files.
However, I have two types of recordes.
One specifies the date and time in the name of the files, but has no metadata.
The other has a counter-type filenae, but contains metadata.
I could use wavinfo or some other package to read these metadata.
But I am left with two different methods of doing the job.
An in addition, I fear that metadata could have different formats dependong on the recorder.
Therefore, indeed, it is much better that I assume a filename contains the date and time in a stabdard way. And that I write a small program to name the files with the method suited for the different recorders.
Thanks again
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.