【问题标题】:Read Nist Wav File in TIMIT database into python numpy array将 TIMIT 数据库中的 Nist Wav 文件读入 python numpy 数组
【发布时间】:2012-04-17 07:33:23
【问题描述】:

这可能吗?从 scikits.audiolab 使用 wavread 时,我似乎遇到了这个错误:

x86_64.egg/scikits/audiolab/pysndfile/matapi.pyc in basic_reader(filename, last, first)
     93             if not hdl.format.file_format == filetype:
     94                 raise ValueError, "%s is not a %s file (is %s)" \
---> 95                       % (filename, filetype, hdl.format.file_format)
     96 
     97             fs = hdl.samplerate

ValueError: si762.wav is not a wav file (is nist)

我猜它无法读取 NIST wav 文件,但有没有另一种方法可以轻松地将它们读入 numpy 数组?如果不是,那么读取数据的最佳方法是什么?

可能重写 audiolab wavread 以识别 nist 标头??

【问题讨论】:

    标签: python numpy scipy speech-recognition


    【解决方案1】:

    回答我自己的问题,因为想通了,但是您可以使用 scikits.audiolab 中的 Sndfile 类,它支持多种读写文件格式,具体取决于您拥有的 libsndfile。然后你只需使用:

    from scikits.audiolab import Sndfile, play
    f = Sndfile(filename, 'r')
    data = f.read_frames(10000)
    play(data) # Just to test the read data
    

    【讨论】:

      【解决方案2】:

      为了扩展 J Spen 的答案,在使用 scikits.audiolab 时,如果您想读取整个文件,而不仅仅是指定数量的帧,您可以使用 Sndfile 类的 nframes 参数来读取整件事情。例如:

      from scikits.audiolab import Sndfile, play
      f = Sndfile(filename, 'r')
      data = f.read_frames(f.nframes)
      play(data) # Just to test the read data
      

      我在文档中找不到对此的任何引用,但它在源代码中。

      【讨论】:

        【解决方案3】:

        与上述答案相反,还有另一种阅读方式 多种格式的音频文件,例如 .wav、.aif、.mp3 等。

        import matplotlib.pyplot as plt
        import soundfile as sf
        import sounddevice as sd
        # https://freewavesamples.com/files/Alesis-Sanctuary-QCard-Crotales-C6.wav
        data, fs = sf.read('Alesis-Sanctuary-QCard-Crotales-C6.wav')
        print(data.shape,fs)
        sd.play(data, fs, blocking=True)
        plt.plot(data)
        plt.show()
        

        输出:

        (88116, 2) 44100
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-05-22
          • 2012-02-03
          • 1970-01-01
          • 2018-06-26
          • 2012-09-01
          • 2013-12-10
          • 1970-01-01
          相关资源
          最近更新 更多