使用Wavefile读取.wav文件时出现Python 3.7错误

时间:2019-04-15 19:35:12

标签: python

我对使用python很陌生,尝试修复某些代码问题时遇到错误。该代码分析声音的频率并将其与枪响进行比较,但我一直遇到错误。不幸的是,尽管我花了几个小时试图修复它,但我还是不能自己修复它。

这是我的代码中有问题的部分:

import wave    
from wave import *
import scipy
from scipy import *
from scipy.io import wavfile as wav
import os
from os import *

os.path.join('/Users/TheBigApple/Downloads/make_call.py', '/Users/TheBigApple/Downloads/gun-gunshot-01.wav')
os.path.join('/Users/TheBigApple/Downloads/make_call.py', '/Users/TheBigApple/Downloads/machine-gun-02.wav')
os.path.join('/Users/TheBigApple/Downloads/make_call.py', '/Users/TheBigApple/Downloads/machine-gun-01.wav')
os.path.join('/Users/TheBigApple/Downloads/make_call.py', '/Users/TheBigApple/Downloads/Prepared SFX Library/1911/A_34P.wav')
os.path.join('/Users/TheBigApple/Downloads/make_call.py', '/Users/TheBigApple/output.wav') 


CHUNK = 1087
FORMAT = pyaudio.paInt16
CHANNELS = 1
WAVE_OUTPUT_FILENAME = "output.wav"
RATE = 2000
RECORD_SECONDS = 10
p = pyaudio.PyAudio()
wf = wave.open("output.wav", 'wb')
stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                frames_per_buffer=CHUNK,
                output=True)
frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
frames.append(data)

data = scipy.io.wavfile.read("output.wav")

wf.setnchannels(1)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.close()

在这一行:

    data = scipy.io.wavfile.read('output.wav'):

我收到以下错误:

/Users/TheBigApple/PycharmProjects/untitled1/venv/bin/python /Users/TheBigApple/Downloads/make_call.py
Traceback (most recent call last):
  File "/Users/TheBigApple/Downloads/make_call.py", line 206, in <module>
    data = scipy.io.wavfile.read("output.wav")
  File "/Users/TheBigApple/PycharmProjects/untitled1/venv/lib/python3.7/site-packages/scipy/io/wavfile.py", line 236, in read
    file_size, is_big_endian = _read_riff_chunk(fid)
  File "/Users/TheBigApple/PycharmProjects/untitled1/venv/lib/python3.7/site-packages/scipy/io/wavfile.py", line 168, in _read_riff_chunk
    "understood.".format(repr(str1)))
ValueError: File format b''... not understood.

Process finished with exit code 1

0 个答案:

没有答案