Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pydub Library Support - Performance Issues in .mp3 to .wav Conversion #812

Open
marcelo061981 opened this issue Aug 29, 2024 · 0 comments
Open

Comments

@marcelo061981
Copy link

Dear Robert,

Good morning.

I am reaching out to request assistance regarding a performance issue we've encountered with the pydub library.

In our operations, we convert .mp3 audio files to .wav format for transcription and analysis. Recently, we've noticed a significant drop in performance during the conversion process. We tested the process on different machines to rule out hardware issues, but the slowdown persists.

If there are any updates or solutions available, we would greatly appreciate it if you could share them with us.


import os
import configparser
from pydub import AudioSegment

diretorio_entrada = 'DownloadsNXT'
diretorio_saida = 'Arquivos_Audio'

os.makedirs(diretorio_saida, exist_ok=True)

arquivos_mp3 = [f for f in os.listdir(diretorio_entrada) if f.endswith('.mp3')]

taxa_amostragem = 44100
config = configparser.ConfigParser()
config.read('par.ini')
duracao_segmento_ms = int(config.get('Geral', 'duracao_segmento_ms'))

total_arquivos = len(arquivos_mp3)

for arquivo_index, arquivo_mp3 in enumerate(arquivos_mp3, start=1):
caminho_mp3 = os.path.join(diretorio_entrada, arquivo_mp3)
audio = AudioSegment.from_mp3(caminho_mp3)

contador_arquivo = 1

for inicio_segmento in range(0, len(audio), duracao_segmento_ms):
    segmento = audio[inicio_segmento:inicio_segmento + duracao_segmento_ms]

    
    nome_base = os.path.splitext(arquivo_mp3)[0]
   
    nome_saida = f'{nome_base}-{contador_arquivo:04d}.wav'  # Usando :04d para formatar o índice com 4 dígitos

    caminho_saida = os.path.join(diretorio_saida, nome_saida)
    segmento.export(caminho_saida, format='wav', codec='libvorbis', parameters=['-ar', str(taxa_amostragem)])

    nome_formatado = f'{nome_saida}'
   
    print(f'Convertendo: {nome_formatado} (Contagem Geral: {arquivo_index}/{total_arquivos})')

   contador_arquivo += 1

print("\nProcesso de Conversão Finalizado com sucesso...")


Best regards,

Marcelo Lima

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant