pip install audioread
python
import audioread
def read_audio_file(path):
with audioread.audio_open(path) as f:
print(f"Channels: {f.channels}")
print(f"Sample rate: {f.samplerate}")
print(f"Duration: {f.duration} seconds")
for audio_frame in f:
pass
read_audio_file("audio.wav")
python
import audioread
def calculate_energy(frame):
energy = sum([x ** 2 for x in frame]) / len(frame)
return energy
def read_audio_file(path):
with audioread.audio_open(path) as f:
for audio_frame in f:
energy = calculate_energy(audio_frame)
print(f"Frame energy: {energy}")
read_audio_file("audio.wav")