Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Audio 带librosa的音频缓冲区_Audio_Buffer_Librosa - Fatal编程技术网

Audio 带librosa的音频缓冲区

Audio 带librosa的音频缓冲区,audio,buffer,librosa,Audio,Buffer,Librosa,在下面的代码中,我创建了一个缓冲区,在每个循环迭代中保存10帧音频文件 import collections import librosa import wave my_buffer = collections.deque(maxlen=10) f = wave.open('Desktop/0963.wav',"rb") num_frames = f.getnframes() for frame in range(num_frames): my_buffer.append(f.readfr

在下面的代码中,我创建了一个缓冲区,在每个循环迭代中保存10帧音频文件

import collections
import librosa
import wave
my_buffer = collections.deque(maxlen=10)
f = wave.open('Desktop/0963.wav',"rb")
num_frames = f.getnframes()
for frame in range(num_frames):
   my_buffer.append(f.readframes(frame))
在缓冲区之外,我需要用librosa获得一个表示每个采样点音频幅度的numpy数组。有什么想法吗?

如果使用,它将直接读取波形文件并将数据加载到numpy阵列。然后您可以根据自己的需求进行切片

scipy.io.wavfile
读取WAV文件并返回采样率(以采样数/秒为单位)和WAV文件中的数据

>>> type(f)
<type 'tuple'>
>>> f
(44100, array([-36,  57, 156, ...,  66,  64,  77], dtype=int16))
>>> 
我的缓冲区内容:

>>> 
[ -36.   57.  156.  198.  191.  126.   70.   42.   43.   62.]
[  69.   71.   83.  117.  159.  177.  151.   89.   14.  -27.]
[ -33.   -4.   21.   38.   42.   66.   94.  134.  144.  142.]
[ 118.  115.  111.  132.  122.  123.  103.  119.  125.  134.]
.....
.....
这里我们有
my_buffer
,每次迭代10帧,您可以输入下一个块。

如果您使用,它将直接读取波形文件并将数据加载到numpy数组。然后您可以根据自己的需求进行切片

scipy.io.wavfile
读取WAV文件并返回采样率(以采样数/秒为单位)和WAV文件中的数据

>>> type(f)
<type 'tuple'>
>>> f
(44100, array([-36,  57, 156, ...,  66,  64,  77], dtype=int16))
>>> 
我的缓冲区内容:

>>> 
[ -36.   57.  156.  198.  191.  126.   70.   42.   43.   62.]
[  69.   71.   83.  117.  159.  177.  151.   89.   14.  -27.]
[ -33.   -4.   21.   38.   42.   66.   94.  134.  144.  142.]
[ 118.  115.  111.  132.  122.  123.  103.  119.  125.  134.]
.....
.....

这里有
my_buffer
,每次迭代10帧,您可以输入到下一个块。

使用
scipy.io.wavfile
添加了答案。请务必查看并让我知道它是否适合您。使用
scipy.io.wavfile
添加答案。一定要检查一下,让我知道它是否适合你。