pyhon中使用librosa处理音频数据

stage 1

  1. jupyter中“浏览”音频:
import IPython.display as ipd
# TO play
ipd.Audio('./noisex-92/001.wav')
  1. librosa官网demo:
from __future__ import print_function
import librosa

# 1. Get the file path to the included audio example
filename = librosa.util.example_audio_file()

# 2. Load the audio as a waveform `y`
#    Store the sampling rate as `sr`
y, sr = librosa.load(filename)

# 3. Run the default beat tracker
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

print('Estimated tempo: {:.2f} beats per minute'.format(tempo))

# 4. Convert the frame indices of beat events into timestamps
beat_times = librosa.frames_to_time(beat_frames, sr=sr)

print('Saving output to beat_times.csv')
librosa.output.times_csv('beat_times.csv', beat_times)

raise NoBackendError() audioread.NoBackendError

跟踪错误栈发现源码中:

    from . import ffdec
    try:
        return ffdec.FFmpegAudioFile(path)
    except DecodeError:
        pass

    # All backends failed!
    raise NoBackendError()

ffdec.py中:

        try:
            self.devnull = open(os.devnull)
            self.proc = popen_multiple(
                COMMANDS,
                ['-i', filename, '-f', 's16le', '-'],
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                stdin=self.devnull,
            )

进一步查看变量COMMANDS:
COMMANDS = ('ffmpeg', 'avconv')
which ffmpeg发现并没有安装ffmpeg
ubuntu16.04安装ffmpeg:

  1. https://tecadmin.net/install-ffmpeg-on-linux/
  2. sudo apt-get update
  3. sudo apt-get install ffmpeg
  4. 如果是windows系统,把ffmeg加入path

参考

[1.] How to Install FFmpeg on Ubuntu 18.04 & 16.04

你可能感兴趣的:(python)