Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

scipy - Numpy Cookbook WAV FILE: File format b"b'RI" not understood

Trying to go through Ivan Idris' Numpy Cookbook. Chapter 2, broadcasting arrays... And I'm receiving this value error. I'm not sure if this is a problem within the scipy package, or something else.

'''
Created on 6 Jul 2014

@author: wrightm
'''
import unittest
import urllib.request
import scipy.io.wavfile
import matplotlib.pyplot
import numpy


class BroadCastingTest(unittest.TestCase):


def test(self):
    response = urllib.request.urlopen('http://www.thesoundarchive.com/austinpowers/smashingbaby.wav')
    print(response.info())
    WAV_FILE = 'smashingbaby.wav'
    filehandle = open(WAV_FILE, 'w')
    filehandle.write(str(response.read()))
    filehandle.close()
    sample_rate, data = scipy.io.wavfile.read(WAV_FILE)
    print("Data type", data.dtype, "Shape", data.shape)

    matplotlib.pyplot.subplot(2, 1, 1)
    matplotlib.pyplot.title("Original")
    matplotlib.pyplot.plot(data)

    newdata = data * 0.2
    newdata = newdata.astype(numpy.uint8)
    print("Data type", newdata.dtype, "Shape", newdata.shape)

    scipy.io.wavfile.write("quiet.wav",
                           sample_rate, newdata)

    matplotlib.pyplot.subplot(2, 1, 2)
    matplotlib.pyplot.title("Quiet")
    matplotlib.pyplot.plot(newdata)

    # matplotlib.pyplot.show()

if __name__ == "__main__":

the exact code from the book (modified for urllib) raises this valueerror:

.../python3.9/site-packages/scipy/io/wavfile.py", line 510, in _read_riff_chunk
raise ValueError(f"File format {repr(str1)} not understood. Only "
ValueError: File format b"b'RI" not understood. Only 'RIFF' and 'RIFX' supported.
question from:https://stackoverflow.com/questions/65916539/numpy-cookbook-wav-file-file-format-bbri-not-understood

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

Just Browsing Browsing

[3] html - How to create even cell spacing within a

2.1m questions

2.1m answers

63 comments

56.5k users

...