从数组中存储的波形播放声音 [英] Playing a sound from a wave form stored in an array

查看:28
本文介绍了从数组中存储的波形播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在 Python 中生成声音,我很好奇如何获取表示波形的 n 数组(采样率为 44100 hz)并播放它.我在这里寻找纯 Python,而不是依赖于不仅仅支持 .wav 格式的库.

解决方案

应该使用库.用纯 Python 编写这一切可能需要数千行代码,才能与音频硬件连接!

带有图书馆,例如audiere,就这么简单:

导入audiereds = audiere.open_device()os = ds.open_array(input_array, 44100)os.play()

还有 pyglet、pygame 和其他许多..

<小时>

上面提到的 audiere 模块似乎不再维护,但我对依赖库的建议保持不变.在此处选择您当前的项目:

https://wiki.python.org/moin/Audio/

https://pythonbasics.org/python-play-sound/

此处没有多少高级 stdlib包含电池"的原因是因为与音频硬件的交互可能非常依赖于平台.

I'm currently experimenting with generating sounds in Python, and I'm curious how I can take a n array representing a waveform (with a sample rate of 44100 hz), and play it. I'm looking for pure Python here, rather than relying on a library that supports more than just .wav format.

解决方案

You should use a library. Writing it all in pure python could be many thousands of lines of code, to interface with the audio hardware!

With a library, e.g. audiere, it will be as simple as this:

import audiere
ds = audiere.open_device()
os = ds.open_array(input_array, 44100)
os.play()

There's also pyglet, pygame, and many others..


Edit: audiere module mentioned above appears no longer maintained, but my advice to rely on a library stays the same. Take your pick of a current project here:

https://wiki.python.org/moin/Audio/

https://pythonbasics.org/python-play-sound/

The reason there's not many high-level stdlib "batteries included" here is because interactions with the audio hardware can be very platform-dependent.

这篇关于从数组中存储的波形播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆