生成波形文件
wavemaker的Python项目详细描述
这个项目位于GitHub。
安装
你需要Python3。我现在不想支持Python2。这是纯的 没有其他依赖项的python包。
我建议您安装最新版本 PyPI带pip:
pip install wavemaker
标准distutils安装也可以工作:
tar xzf wavemaker-*.tar.gz cd wavemaker-* python setup.py install
用法
命令行工具称为make_wave。使用方法如下:
make_wave sine-wave.wav
内置了更多帮助:
$ make_wave --help usage: make_wave [-h] [--waveform {sine}] [--frequency FREQUENCY] [--amplitude AMPLITUDE] [--duration DURATION] [--sample_rate SAMPLE_RATE] [--sample_size {16}] output_path Generate WAVE files. positional arguments: output_path The path to the resulting WAVE file optional arguments: -h, --help show this help message and exit --waveform {sine} The shape of the signal being generated (default: sine) --frequency FREQUENCY The oscillating rate of the wave. A non-negative float, in Hz (default: 440.0) --amplitude AMPLITUDE The amplitude of the wave. A float between 0.0 and 1.0 (default: 1.0) --duration DURATION The time duration of the signal. A non-negative float, in seconds (default: 1.0) --sample_rate SAMPLE_RATE The number of samples per second. A non-negative int, in Hz (default: 44100) --sample_size {16} The number of bits used to store each sample (default: 16)
API
只有一个公共api函数调用。它采用的参数与 命令行工具用作关键字参数。请参阅docstring了解更多信息:
write_wave_file(output_path, waveform='sine', frequency=440.0, amplitude=1.0, duration=1.0, sample_rate=44100, sample_size=16)
基本用法:
import wavemaker wavemaker.write_wave_file('sine-wave.wav')