标签: wave

Python:波浪的可视化

我想编程一个简单的波传播可视化.我尝试使用visual python(VPython),但程序非常慢.我现在想要使用二维可视化.你能推荐哪个模块?Tkinter的?Matplotlib?

对于计算我使用numpy/scipy因为它很快.提前致谢.

编辑:你认为matplotlib是一个不错的选择吗?它看起来非常强大.

编辑:我真的卡住了.请帮我!

python visualization physics wave

5
推荐指数
0
解决办法
1589
查看次数

需要一个从Midi生成WAVE的库

我有大约80个用MIDI编写的乐曲,我想用声音库将它们转换成WAVE.因此,它们可以在所有计算机上播放并发出相同的声音.是否有可以自动执行此操作的库?

最好是在C#中,但其他编程语言也可以.

.net midi wave

5
推荐指数
0
解决办法
1309
查看次数

python wave模块可以接受StringIO对象吗

我正在尝试使用wave模块来读取python中的wav文件。

我的应用程序不常见的是我没有使用文件或文件名来读取wav文件,而是将wav文件放在缓冲区中。

这就是我在做什么

import StringIO

buffer = StringIO.StringIO()
buffer.output(wav_buffer)

file = wave.open(buffer, 'r')
Run Code Online (Sandbox Code Playgroud)

但是我EOFError运行它时得到了...

  File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/wave.py", line 493, in open
return Wave_read(f)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/wave.py", line 163, in __init__
self.initfp(f)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/wave.py", line 128, in initfp
self._file = Chunk(file, bigendian = 0)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/chunk.py", line 63, in __init__
raise EOFError
Run Code Online (Sandbox Code Playgroud)

我知道这些StringIO东西可以用于创建wav文件,并且我尝试了以下操作,并且效果很好

import StringIO


buffer = StringIO.StringIO()
audio_out = wave.open(buffer, 'w')
audio_out.setframerate(m.getRate())
audio_out.setsampwidth(2)
audio_out.setcomptype('NONE', 'not compressed')
audio_out.setnchannels(1)

audio_out.writeframes(raw_audio)
audio_out.close()
buffer.flush()

# these lines do …
Run Code Online (Sandbox Code Playgroud)

python audio wave

5
推荐指数
1
解决办法
1866
查看次数

将iphone中录制的声音从一种格式转换为另一种格式,将wav转换为mp3

我正在尝试录制一些音频并将其转换为其他声音格式.我正在使用AVAudioRecorder类进行录制,这些是我使用的录制设置.

 NSDictionary *recordSetting = [[NSMutableDictionary alloc] init];
 [recordSetting setValue:[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];//kAudioFormatMicrosoftGSM,kAudioFormatLinearPCM
 [recordSetting setValue:[NSNumber numberWithFloat:8000] forKey:AVSampleRateKey]; 
 [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
 [recordSetting setValue :[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
 [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
 [recordSetting setValue :[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];
Run Code Online (Sandbox Code Playgroud)

录音工作得很漂亮.现在我想将此声音文件转换为mp3格式.我可以使用AudioToolBox框架执行此操作.我试过这个

 AudioStreamBasicDescription sourceFormat,destinationFormat;
 //Setting up source Format setting..here wav
 sourceFormat.mSampleRate   = 8000.0;
 sourceFormat.mFormatID    = kAudioFormatLinearPCM;
 sourceFormat.mFormatFlags   = kAudioFormatFlagIsSignedInteger ;
 sourceFormat.mBytesPerPacket  = 4;
 sourceFormat.mFramesPerPacket  = 1;
 sourceFormat.mBytesPerFrame   = 4;
 sourceFormat.mChannelsPerFrame  = 2;
 sourceFormat.mBitsPerChannel  = 16;

 destinationFormat.mSampleRate  = 8000.0;
 destinationFormat.mFormatID   = kAudioFormatMPEGLayer3;
 destinationFormat.mFormatFlags  = 0;
 destinationFormat.mBytesPerPacket = …
Run Code Online (Sandbox Code Playgroud)

iphone mp3 wave audiotoolbox

5
推荐指数
1
解决办法
2216
查看次数

C++ - 播放由正弦波产生的音调

嘿大家,我正在试图弄清楚如何播放我用正弦波产生的音调.

这是我的代码:

#include <iostream>
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#include <Math.h>

using namespace std;

int main (int argc, char * const argv[]) {

    int number = 0;
    int i, size;
    double const Pi=4*atan(1); 
    cout << "Enter number of seconds:" << endl;
    scanf("%d", &number);
    size = 44100*number;
    unsigned char buffer [size]; //buffer array

    for(i = 0; i < size; i++){
        buffer[i] = (char)sin((2*Pi*440)/(44100*i))*127;
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

显然它目前没有做任何事情,因为我不知道如何播放缓冲区.我不想生成一个wav文件,也不想加载一个.我只是想回放我生成的缓冲区.

我目前正在使用Mac OS X,并尝试使用OpenAL方法 - 但是我发现alut和alu不再是它的一部分了,如果我尝试使用它,那么事实证明它无论如何都被摧毁了.我也尝试过包含QAudioOutput,但出于某种原因,它似乎并不在我的Mac上.

我只想简单回放我创造的音调.有没有人能指点我的东西?

谢谢堆!!!

c++ audio trigonometry generator wave

5
推荐指数
1
解决办法
2万
查看次数

在未知的时间播放正弦波

整天我都在寻找一些教程或一段代码,"只是"为"无限"时间播放简单的正弦波.我知道这听起来有点疯狂.

但我希望能够及时改变音调的频率 - 增加它.想象一下,我想播放音调A,并在每个3ms的"+5"频率步长中将其增加到C(这实际上只是示例),不想有空闲的地方,停止音调.

可能吗?或者你能帮帮我吗?

c# audio trigonometry wave

5
推荐指数
1
解决办法
2152
查看次数

将3字节立体声WAV文件转换为numpy数组

我已经获得了一个连续水下记录的大型WAV文件,我想将其转换为numpy数组进行分析.我正在努力做到这一点.

到目前为止,我有:

import numpy as np
import scipy as sp
import wave as wv
import struct

wavefile = wv.open(filename,'r')
(nchannels,sampwidth,framerate,nframes,comptype,compname) = wavefile.getparams()

// read a sample as example

wavedata =wavefile.readframes(1)
Run Code Online (Sandbox Code Playgroud)

第一帧看起来像这样:'\ xcd\xbc\xff @\x01\x00'.我试图使用struct解压缩它,但解压缩任何我得到以下错误:" str大小不匹配格式 ".我想这与Python struct无法处理24位数据有关.

wave文件的参数如下所示:

  • nchannels = 2
  • sampwidth = 3
  • 帧率= 48000
  • 将为nframes = 283516532L
  • comptype = 'NONE'
  • compname ='not compressed'

有人知道如何将24位立体声WAV文件读入一个numpy阵列?

python numpy wav wave

5
推荐指数
2
解决办法
1955
查看次数

Python - 超过4gb的Wave文件:struct.error:'L'格式需要0 <= number <= 4294967295

我试图在我的python脚本中创建超过4GB的音频波形文件,但是我收到错误.这是一个重现问题的简短脚本.有人可以告诉我为什么我会遇到这样的错误以及如何修复它,或者它可能是一个错误?

我尝试使用python 2.7和3.4,但两者都有相同的错误.

# script for python 2
import wave

# create a large (>4gb) file
wf = wave.open("foo.wav", "w")
wf.setnchannels(2)
wf.setsampwidth(2)
wf.setframerate(44100)
text = 'a' * 1024**2
for i in xrange(5 * 1024):
    print i
    wf.writeframes(text)
wf.close()
Run Code Online (Sandbox Code Playgroud)

输出:

4088
4089
4090
4091
4092
4093
4094
4095
Traceback (most recent call last):
  File "test.py", line 16, in <module>
    wf.writeframes(text)
  File "/usr/lib/python2.7/wave.py", line 444, in writeframes
    self._patchheader()
  File "/usr/lib/python2.7/wave.py", line 496, in _patchheader
    self._file.write(struct.pack('<L', 36 + self._datawritten))
struct.error: 'L' format requires …
Run Code Online (Sandbox Code Playgroud)

python wave

5
推荐指数
1
解决办法
1242
查看次数

如何使用Python正确解码.wav

我正在编码WAVE音频文件的基本频率analisys,但是在从WAVE帧转换为整数时遇到麻烦。

这是我的代码的相关部分:

import wave
track = wave.open('/some_path/my_audio.wav', 'r')

byt_depth = track.getsampwidth() #Byte depth of the file in BYTES
frame_rate = track.getframerate()
buf_size = 512

def byt_sum (word):
#convert a string of n bytes into an int in [0;8**n-1]
    return sum( (256**k)*word[k] for k in range(len(word)) )

raw_buf = track.readframes(buf_size)
'''
One frame is a string of n bytes, where n = byt_depth.
For instance, with a 24bits-encoded file, track.readframe(1) could be:
b'\xff\xfe\xfe'.
raw_buf[n] returns an int in [0;255]
'''

sample_buf …
Run Code Online (Sandbox Code Playgroud)

python audio int byte wave

5
推荐指数
1
解决办法
2276
查看次数

wave.error:#个通道未指定

我正在尝试使用wave模块编辑wav文件的长度。但是似乎无法到达任何地方,因为我一直收到相同的错误,即未指定通道数。尽管如此,当我写一些东西来查看通道数时,仍然出现该错误,或​​者当我尝试设置通道数时,如下所示:

def editLength(wavFile):
   file = wave.open(wavFile, 'w')
   file.setnchannels(file.getnchannels())
   x = file.getnchannels()
   print (x)
Run Code Online (Sandbox Code Playgroud)

python wave

5
推荐指数
1
解决办法
853
查看次数

标签 统计

wave ×10

python ×6

audio ×4

trigonometry ×2

.net ×1

audiotoolbox ×1

byte ×1

c# ×1

c++ ×1

generator ×1

int ×1

iphone ×1

midi ×1

mp3 ×1

numpy ×1

physics ×1

visualization ×1

wav ×1