简体   繁体   中英

How to generate a Sine wave tone on python 3

I am wanting to generate a sinusoidal tone using python 3 of 1kHz frequency. I found an old question on stackoverflow (old question) about it but that was using the pyaudio which is for python 2.

Is there any other way I can do this using python 3?


Error when I try an install tone scale

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.

The tonescale installation instructions suggest using the python3 version of pyaudio: python3-pyaudio.

There is also pygame .

The pyaudio install instructions for Windows suggest that it should go smoothly, as binary wheels are provided. However they do mention that in unusual situations a compilation of PortAudio may be needed.

You might want to try using a downrev wheel from the archive .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM