python - 如何在python 3上生成正弦波音调

标签 python python-3.x numpy audio

我想使用1kHz频率的python 3生成正弦音调。我在stackoverflow (old question)上发现了一个老问题,但它使用的是python 2的pyaudio

我还有其他方法可以使用python 3吗?

尝试安装音阶时出错

Successfully built tonescale propyte shijian sklearn docopt pyprel pytg technico
lor DictObject backcall pyrsistent prometheus-client pandocfilters
Failed to build pyaudio
Installing collected packages: docopt, python-magic, websocket-client, pushbulle
t.py, pickleshare, backcall, ipython-genutils, decorator, traitlets, pygments, p
rompt-toolkit, parso, jedi, colorama, ipython, tornado, pyzmq, jupyter-core, jup
yter-client, ipykernel, pyrsistent, jsonschema, nbformat, entrypoints, pandocfil
ters, webencodings, bleach, mistune, testpath, MarkupSafe, jinja2, defusedxml, n
bconvert, prometheus-client, pywinpty, terminado, Send2Trash, notebook, widgetsn
bextension, ipywidgets, kiwisolver, cycler, pyparsing, matplotlib, scipy, seabor
n, joblib, scikit-learn, sklearn, technicolor, shijian, pyprel, luckydonald-util
s, DictObject, pytg, psutil, propyte, pyaudio, tonescale
  Running setup.py install for pyaudio ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\myUser\appdata\local\programs\python\python37-32\python.exe
' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\myUser\\Ap
pData\\Local\\Temp\\pip-install-zn_0i9s8\\pyaudio\\setup.py'"'"'; __file__='"'"'
C:\\Users\\myUser\\AppData\\Local\\Temp\\pip-install-zn_0i9s8\\pyaudio\\setup.py'"'
"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'
"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'
))' install --record 'C:\Users\myUser\AppData\Local\Temp\pip-record-5j63osr6\instal
l-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\myUser\AppData\Local\Temp\pip-install-zn_0i9s8\pyaudio\
    Complete output (9 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    copying src\pyaudio.py -> build\lib.win32-3.7
    running build_ext
    building '_portaudio' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual
C++ Build Tools": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\myUser\appdata\local\progr
ams\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.
argv[0] = '"'"'C:\\Users\\myUser\\AppData\\Local\\Temp\\pip-install-zn_0i9s8\\pyaud
io\\setup.py'"'"'; __file__='"'"'C:\\Users\\myUser\\AppData\\Local\\Temp\\pip-insta
ll-zn_0i9s8\\pyaudio\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__
file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compi
le(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\myUser\AppData\Loca
l\Temp\pip-record-5j63osr6\install-record.txt' --single-version-externally-manag
ed --compile Check the logs for full command output.

最佳答案

tonescale installation instructions
建议使用pyaudio的python3版本:python3-pyaudio。

还有pygame

Windows的pyaudio install instructions建议
它提供了二进制车轮,因此应该平稳运行。
但是他们确实提到在异常情况下
可能需要PortAudio的编译。

您可能想尝试使用archive中的downrev轮。

关于python - 如何在python 3上生成正弦波音调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57211727/

相关文章:

python - 为什么我的 CreateAPIView 不显示产品和商店类别字段?

python - 如何创建自定义 crontab?

python - 用零填充列表中的数组

python - 向量化切片的最小值和最大值可能吗?

python - 仅访问嵌套字典列表中的一个键并使用 matplotlib 绘制它

python - 在保持内部顺序的同时打乱 DataFrame

python - 如何在给定的 pd.DatetimeIndex 中仅选择每月的最后 n 天

python - 如何验证 namedtuple 值?

python - 来自元组的稀疏数组

python - pandas 数据框的高效矩阵化