Datasets:
import pandas as pd | |
from pydub import AudioSegment | |
from pydub.utils import mediainfo | |
def duration(file_name): | |
audio = AudioSegment.from_file(file_name) | |
return audio.duration_seconds | |
file = 'users_ayahs.csv' | |
file_out = 'users_ayahs_new.csv' | |
df = pd.read_csv(file) | |
# Convert the dictionary into DataFrame | |
df = pd.DataFrame(df) | |
df['duration_in_seconds'] = df.apply(lambda row: duration(row['file_name']), axis=1) | |
df['quran_id'] = df['quran_id'].astype(str).str.pad(6, fillchar='0') | |
df.to_csv(file_out, encoding='utf-8', index=False) | |