Processamento de Linguagem Falada em Python
Daniel Bourke
Machine Learning Engineer/YouTube Creator
$ pip install pydub
.wav, instale ffmpeg em ffmpeg.org# Importar a classe principal do PyDub
from pydub import AudioSegment
# Importar um arquivo de áudio
wav_file = AudioSegment.from_file(file="wav_file.wav", format="wav")
# Parâmetro format apenas para legibilidade
wav_file = AudioSegment.from_file(file="wav_file.wav")
type(wav_file)
pydub.audio_segment.AudioSegment
# Instalar simpleaudio para tocar wav
$pip install simpleaudio
# Importar a função play
from pydub.playback import play
# Importar arquivo de áudio
wav_file = AudioSegment.from_file(file="wav_file.wav")
# Reproduzir o arquivo
play(wav_file)
# Importar arquivos de áudio wav_file = AudioSegment.from_file(file="wav_file.wav") two_speakers = AudioSegment.from_file(file="two_speakers.wav")# Verificar número de canais wav_file.channels, two_speakers.channels
1, 2
wav_file.frame_rate
480000
# Número de bytes por amostra
wav_file.sample_width
2
# Amplitude máxima
wav_file.max
8488
# Duração do arquivo (ms)
len(wav_file)
3284
# Alterar ATTRIBUTENAME de AudioSegment para x
changeed_audio_segment = audio_segment.set_ATTRIBUTENAME(x)
# Alterar sample width para 1
wav_file_width_1 = wav_file.sample_width(1)
wav_file_width_1.sample_width
1
# Alterar sample rate
wav_file_16k = wav_file.frame_rate(16000)
wav_file_16k.frame_rate
16000
# Alterar número de canais
wav_file_1_channel = wav_file.set_channels(1)
wav_file_1_channel.channels
1
Processamento de Linguagem Falada em Python