简体   繁体   English

如何使用 wavio api 从数据中写入.wav 文件

[英]How to write .wav file from data using wavio api

I'm using WAVIO python API to write data to a.wav file.我正在使用 WAVIO python API 将数据写入 a.wav 文件。 In order to test this api, First I read data.wav file and then I want to generate.wav containing the same data of the input.wav file, but I got an error while writing data to the output wav file.为了测试这个 api,我首先读取 data.wav 文件,然后我想生成包含与 input.wav 文件相同数据的.wav,但是在将数据写入 output wav 文件时出现错误。

import numpy as np
import wavio

wa = wavio.read("s24.wav")  #Read a .wav file
print("x= "+str(wa.data))   #Data
print("rate= "+str(wa.rate))    #Rate
print("sampwidth= "+str(wa.sampwidth))  #sampwidth
wavio.write("sine24_output", wa.data, wa.rate,wa.sampwidth)   #Error is here

Error is:错误是:

Traceback (most recent call last):回溯(最近一次通话最后):

  File "C:/Users/user/Desktop/Wav2Bytes/wavii.py", line 24, in <module>
    wavio.write("sine24_output", wa.data, wa.rate,wa.sampwidth)   #Write a .wav file. Error is here
  File "C:\Program Files (x86)\Python\lib\site-packages\wavio.py", line 363, in write
    vmin, vmax = scale
TypeError: cannot unpack non-iterable int object

You are missing the argument's name sampwidth .您缺少参数的名称sampwidth According to the docs , there are 5 arguments, if you don't specify the name sampwidth , it will instead set scale to wa.sampwidth .根据文档,有 5 个 arguments,如果您不指定名称sampwidth ,它将改为将scale设置为wa.sampwidth Anyway just use this:无论如何,只需使用这个:

wavio.write("sine24_output", wa.data, wa.rate,sampwidth=wa.sampwidth)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM