import array from pydub import AudioSegment from pydub utils import ge

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import array
from pydub import AudioSegment
from pydub.utils import get_array_type
import numpy as np
import scipy.io.wavfile as wav
import pandas as pd
def read_mp3(inputFile):
sound = AudioSegment.from_file(inputFile)
left = sound.split_to_mono()[0]
bit_depth = left.sample_width * 8
array_type = get_array_type(bit_depth)
return np.array(array.array(array_type, left._data))
audioname = 'test.wav'
if 'wav' in audio_filename:
fs, audio = wav.read(audio_filename)
if fs != 16000:
audio = signal.resample(audio, 16000)
fs = 16000
else:
audio = read_mp3(audio_filename)