Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...