从数组中存储的波形播放声音

编程入门 行业动态 更新时间:2024-10-07 16:20:51
本文介绍了从数组中存储的波形播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我目前正在尝试在 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/moin/Audio/

https://pythonbasics/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/moin/Audio/

https://pythonbasics/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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 21:11:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1142745.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:波形   组中   声音

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!