My personal website.
Would be great if you report any issues you encounter. Thank you ♥
A fork to record speaker output with python. PyAudio with PortAudio for Windows | Extended | Loopback | WASAPI | Latest precompiled Version
License: MIT License
My personal website.
Would be great if you report any issues you encounter. Thank you ♥
PyAudio is not for python3.8, I hope you to update it ,thank you very much.
Hi,
I just download x86_64_python3.tar.gz.
Errors message is as below:
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "c:\users\xx\appdata\local\programs\python\python36\lib\tokenize.py", line 452, in open
buffer = _builtin_open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\xx\AppData\Local\Temp\pip-229ndf1p-build\setup.py'
Command "python setup.py egg_info" failed with error code 1 in C:\Users\xxx\AppData\Local\Temp\pip-229ndf1p-build\
Python 3.8 is updated.
The latest .whl file is for Python 3.7, not Python 3.8, so it cannot be installed correctly.
It is necessary for update .whl file for Python 3.8 because it is difficult for me to build an environment for Portaudio on Windows Server.
Hey,
Just wanted to say thanks, this worked perfectly.
Just had a question about wasapi and mme:
I noticed a lot of my output devices were mme, and it looks like this port doesn't like loopback on mme api devices. Is this a bug? Or just a limitation?
If you run your sample script, if i select a mme output device it tells me its a input device (because it's not wasapi) and says its not supported.
There is a Pyaudio stream that takes input from mic and text received is processed. I have created another function main that uses silence detection class in which again Pyaudio is created and closed. It was working fine.
As per my requirement, I created process and call main() in process. and start the multiprocess environment. But this I got below error.
Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1904
Expression 'PaAlsaStreamComponent_Initialize( &self->capture, alsaApi, inParams, StreamDirection_In, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2171
Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2840
[Errno -9993] Illegal combination of I/O devices
The code used was the same, the only change was now main() is not directly called this time as a function instead of a process.
Any help would be appreciated.
I'm very excited to use this program but am having difficulties with the install process.
Sorry, I'm very inexperienced with coding and install and whenever I try the process on my mac, I get this:
ERROR: PyAudio-0.2.11-cp37-cp37m-win_amd64.whl is not a supported wheel on this platform.
Any solution or help would be greatly appreciated!
Best,
Eric
Hello, I love your work. Thank you for sharing
Can I build this for 32bit env?
Hi,
can anyone share the portaudio.pyd files for the 32bit version along with ASIO drivers support since the present code supports loopback only for WASAPI. For my experiment, I need ASIO support. If is it possible please share me as soon as possible.
I have tried adding support for ASIO but getting errors during build and installation through setup.py like cl.exe not found. But for my experiment I need portaudio.pyd files and pyaudio.py as soon as possible. Any help is really helpful to go forward in my experiment.
Thanks in advance.
reference:
As we have already portaduio.pyd files for x64 machine for WASAPI at this link -- https://github.com/Geo-Joy/pyaudio_portaudio_loopback/releases
I installed pyaudio and portaudio with 'conda install pyaudio' but get this error 'init() got an unexpected keyword argument 'as_loopback'
Someone had the same problem, but closed the topic without explaining the solution.
How can I resolve it?
Thanks
I'm using this with Python3.7 (used the .msi installer) and after the audio stream goes on for a while (as_loopback = true), speaker output starts inputting itself into microphone's left channel and it stays that way until I restart my system.
The script is using system audio output as input to do frequency cutoffs (scipy butterworth), some analysis and write results onto a file. Script has nothing to do with microphone. Only device used is Speakers with (as_loopback=true) parameter.
Signing out and back in again, stopping the python script, unplugging and plugging mic back in, nothing else helps. It's quite annoying since I use my mic for meetings and all, and all speaker output can be heard in left channel of my mic. At times I'm doing rendering/encoding in background that takes a few hours each time and restarting over and over isn't a good solution.
Happens consistently, every time I run the script longer than a few minutes. Fixes consistently when I restart.
Is there any update or alternative for Python 3.9?
def record(filename, seconds):
chunk = 1024 # Record in chunks of 1024 samples
sample_format = pyaudio.paInt16 # 16 bits per sample
channels = 2
fs = 44100 # Record at 44100 samples per second
seconds = seconds
filename = filename
p = pyaudio.PyAudio() # Create an interface to PortAudio
print('Recording')
stream = p.open(format=sample_format,
channels=channels,
rate=fs,
frames_per_buffer=chunk,
input=True)
frames = [] # Initialize array to store frames
# Store data in chunks for 3 seconds
for i in range(0, int(fs / chunk * seconds)):
data = stream.read(chunk)
frames.append(data)
# Stop and close the stream
stream.stop_stream()
stream.close()
# Terminate the PortAudio interface
p.terminate()
print('Finished recording')
# Save the recorded data as a WAV file
wf = wave.open(filename, 'wb')
wf.setnchannels(channels)
wf.setsampwidth(p.get_sample_size(sample_format))
wf.setframerate(fs)
wf.writeframes(b''.join(frames))
wf.close()
# record("a.wav", 3)
# oscillogram_spectrum("./a.wav")
if __name__ == '__main__':
t1 = threading.Thread(target=record, args=("b.wav", 4))
t2 = threading.Thread(target=record, args=("c.wav", 4))
t1.start()
t2.start()
I built the files and made the commands with cygwin like you told.I made the script using your example this way:
import wave
defaultframes = 512
class textcolors:
blue = '\033[94m'
green = '\033[92m'
warning = '\033[93m'
fail = '\033[91m'
end = '\033[0m'
recorded_frames = []
device_info = {}
useloopback = False
recordtime = 5
#Use module
p = pyaudio.PyAudio()
#Set default to first in list or ask Windows
try:
default_device_index = p.get_default_input_device_info()
except IOError:
default_device_index = -1
#Select Device
print (textcolors.blue + "Available devices:\n" + textcolors.end)
for i in range(0, p.get_device_count()):
info = p.get_device_info_by_index(i)
print (textcolors.green + str(info["index"]) + textcolors.end + ": \t %s \n \t %s \n" % (info["name"], p.get_host_api_info_by_index(info["hostApi"])["name"]))
if default_device_index == -1:
default_device_index = info["index"]
#Handle no devices available
if default_device_index == -1:
print (textcolors.fail + "No device available. Quitting." + textcolors.end)
exit()
#Get input or default
device_id = int(input("Choose device [" + textcolors.blue + str(default_device_index) + textcolors.end + "]: ") or default_device_index)
print ("")
#Get device info
try:
device_info = p.get_device_info_by_index(device_id)
except IOError:
device_info = p.get_device_info_by_index(default_device_index)
print (textcolors.warning + "Selection not available, using default." + textcolors.end)
#Choose between loopback or standard mode
is_input = device_info["maxInputChannels"] > 0
is_wasapi = (p.get_host_api_info_by_index(device_info["hostApi"])["name"]).find("WASAPI") != -1
if is_input:
print (textcolors.blue + "Selection is input using standard mode.\n" + textcolors.end)
else:
if is_wasapi:
useloopback = True;
print (textcolors.green + "Selection is output. Using loopback mode.\n" + textcolors.end)
else:
print (textcolors.fail + "Selection is output and does not support loopback mode. Quitting.\n" + textcolors.end)
exit()
recordtime = int(input("Record time in seconds [" + textcolors.blue + str(recordtime) + textcolors.end + "]: ") or recordtime)
#Open stream
channelcount = device_info["maxInputChannels"] if (device_info["maxOutputChannels"] < device_info["maxInputChannels"]) else device_info["maxOutputChannels"]
stream = p.open(format = pyaudio.paInt16,
channels = channelcount,
rate = int(device_info["defaultSampleRate"]),
input = True,
frames_per_buffer = defaultframes,
input_device_index = device_info["index"],
as_loopback = True)
#Start Recording
print (textcolors.blue + "Starting..." + textcolors.end)
for i in range(0, int(int(device_info["defaultSampleRate"]) / defaultframes * recordtime)):
recorded_frames.append(stream.read(defaultframes))
print (".")
print (textcolors.blue + "End." + textcolors.end)
#Stop Recording
stream.stop_stream()
stream.close()
#Close module
p.terminate()
filename = raw_input("Save as [" + textcolors.blue + "out.wav" + textcolors.end + "]: ") or "out.wav"
waveFile = wave.open(filename, 'wb')
waveFile.setnchannels(channelcount)
waveFile.setsampwidth(p.get_sample_size(pyaudio.paInt16))
waveFile.setframerate(int(device_info["defaultSampleRate"]))
waveFile.writeframes(b''.join(recorded_frames))
waveFile.close()
However the following error occurs: TypeError: init() got an unexpected keyword argument 'as_loopback'
Anyone here know what could be the issue?
Thanks
Thank you for putting this package together!
I have had great success using this with the simple installer on 3.5.
Could you please explain how to use this with Python 2.7? I have downloaded your standalone files (pyaudio.py, _portaudio.dll) within the standalone folder and dropped them in my project directory. I get a no module found with name _portaudio.dll. Could you please explain how to use this with 2.7. Or have you built an installer for 2.7 like you did with 3.5?
Thank you
I've manage to use the loopback with the speaker but i was wondering, can we use loopback for the mic too?
What i mean by that, i want to be able to send audio to the mic from a wav file to simulate a user speaking. It's because i have an application(Teams) that listen on the microphone.
I've try that so far and it's not working(Error : Wrong number of channel):
import pyaudio
import wave
filename = 'output.wav'
# Set chunk size of 1024 samples per data frame
chunk = 1024
# Open the sound file
wf = wave.open(filename, 'rb')
# Create an interface to PortAudio
p = pyaudio.PyAudio()
print(wf.getnchannels())
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True,
output_device_index=7,# The mic wit WAS Host API
as_loopback=True)
# Read data in chunks
data = wf.readframes(chunk)
# Play the sound by writing the audio data to the stream
while data != '':
stream.write(data)
data = wf.readframes(chunk)
# Close and terminate the stream
stream.close()
p.terminate()
Might it be possible to create a windows 32 bit whl pre-build for inclusion at https://github.com/intxcc/pyaudio_portaudio/releases ?
No issues, here. Just a big thank you! ❤️
Hi intxcc,
when I try to install PyAudio-0.2.11-cp36-cp36m-win_amd64.whl, this is the result:
PS C:\Windows\system32> python -m pip install "C:\Users\Claudio\Downloads\PyAudio-0.2.11-cp36-cp36m-win_amd64.whl"
PyAudio-0.2.11-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform.
Can you made another build for Python 3.7? 😃
Or can you tell me how use latest library, without recompile all?
Compiled fine on 64bit and release in microsoft studio, located Lib file to verify.
Struggling with the last step
src/_portaudiomodule.c(27): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
error: command 'C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.33.31629\bin\HostX86\x64\cl.exe' failed with exit code 2
I have installed the msi installer, and tried to start recording when I have got this error message:
ModuleNotFoundError: No module named '_portaudio'
I have python 3.6 installed.
Do I have to install portaudio separately?
The precompiled binary that is given only supports amd64, which I believe is Linux. Do we have a Win32 version?
TypeError Traceback (most recent call last)
in
75 frames_per_buffer = defaultframes,
76 input_device_index = device_info["index"],
---> 77 as_loopback = useloopback)
78
79 #Start Recording
c:\users\dmolp\appdata\local\programs\python\python37\lib\site-packages\pyaudio.py in open(self, *args, **kwargs)
748 :py:func:Stream.__init__
for parameter details.
749
--> 750 :returns: A new :py:class:Stream
751 """
752
TypeError: init() got an unexpected keyword argument 'as_loopback'
Windows 10 Home. Python 3.7.2. Installed from PyAudio-0.2.11-cp37-cp37m-win_amd64.whl
After running this:
python ./setup.py install --static-link
These logs show up:
running install
running build
running build_py
copying src\pyaudio.py -> build\lib.win-amd64-2.7
running build_ext
building '_portaudio' extension
error: Unable to find vcvarsall.bat
Any solution??
My PATH is also set to Auxiliary\Build directory. But still showing the error
And if I try this command:
python setup.py install build --compiler=mingw32
this error shows:
running install
running build
running build_py
copying src\pyaudio.py -> build\lib.win-amd64-2.7
running build_ext
error: Error
When creating a stream with as_loopback=True
, the read
method on the created stream will block until audio is being played. I'm not sure if this is the desired behavior, but it's certainly unexpected for me. I would suggest the read method to instead just return silence, instead of blocking until data is available.
This blog post mentions this problem, with the solution of running an application which just outputs silence, but I don't think this is a particularly useful solution for a library.
Is the recording of the soundcard output only available for WASAPI drivers?
https://github.com/intxcc/pyaudio_portaudio/blob/master/example/echo_python3.py#L66
In my case, it doesn't work with device number 0, 1, 2, 3, but only number 4 below.
Is that normal?
0: Microsoft Sound Mapper - Input
MME
1: Microphone interne (Conexant 20
MME
2: Microsoft Sound Mapper - Output
MME
3: Speakers (Conexant 20672 SmartA
MME
4: Speakers (Conexant 20672 SmartAudio HD)
Windows WASAPI
Also, what is the specific part in your fork @intxcc?
Did you add something specific to portaudio (in C code?) or pyaudio or both?
As of today (oct 2020), is loopback device also included in the original "pyaudio" project?
Can the installation instructions be improved? I do not understand how to get this code working on my machine. After msi installer, No module named 'pyaudio'.
== update ==
c:\program files\python36\include\pyconfig.h(119): warning C4005: 'MS_WIN64': macro redefinition
c:\program files\python36\include\pyconfig.h(119): note: command-line arguments: see previous definition of 'MS_WIN64'
src/_portaudiomodule.c(29): fatal error C1083: Cannot open include file: 'portaudio.h': No such file or directory
I want to play voice in multithreading.one child thread play voice,parent thread send voice info to child and control child to stop play .
I got some trouble.This is a reduced version of the program.
I got crash,but not catch any exception,output:
0
#child loop first
[Errno Unanticipated host error] -9999
#when parent stop_stream(),child catch IOError,
0
#child loop second
but in my complete code this no problem in 1~2h,then it crash and not catch any exception.
if delete the 42 line
this reduced can run perfectly at last 10h,this takes too much time,i just test this once,it looks no problem.
but in my complete code,there no stream.close() no time.sleep(),it just run 10~30min,then pa.open() raise IOError : [Errno Illegal combination of I/O devices] -9993,cannot play anymore.if restart this pa.open() raise other IOError:('Invalid sample rate', -9997).I can't use pyaudio anymore except reboot computer.
i think this problem in complete code maybe sometimes there no sleep to wait stop_stream() done work .if that,how can i know stop_stream() done its work?
if not,how can i using pyaudio like this in multithreading?
thanks for help!
I followed the process https://github.com/intxcc/pyaudio_portaudio#microsoft-visual-studio-2017.
After successfully building portaudio, I got file pyaudio\portaudio-v19\build\msvc\x64\Release\portaudio.lib.
Then I ran python.exe .\setup.py install --static-link in powershell as administrator, but got errors bellow:
Creating library build\temp.win32-3.7\Release\src\_portaudio.cp37-win32.lib and object build\temp.win32-3.7\Release\src\_portaudio.cp37-win32.exp
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_StartStream
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetStreamTime
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_IsFormatSupported
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetStreamWriteAvailable
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetVersion
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetDefaultOutputDevice
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetDefaultInputDevice
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_HostApiTypeIdToHostApiIndex
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_WriteStream
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_CloseStream
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetStreamCpuLoad
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_OpenStream
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_Terminate
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetVersionText
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_IsStreamStopped
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_Initialize
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_HostApiDeviceIndexToDeviceIndex
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_AbortStream
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetDeviceCount
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_IsStreamActive
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetErrorText
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetSampleSize
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_ReadStream
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetDeviceInfo
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetDefaultHostApi
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetHostApiInfo
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetStreamReadAvailable
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetHostApiCount
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_GetStreamInfo
_portaudiomodule.obj : error LNK2001: unresolved external symbol _Pa_StopStream
build\lib.win32-3.7\_portaudio.cp37-win32.pyd : fatal error LNK1120: 30 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Tools\\MSVC\\14.15.26726\\bin\\HostX86\\x86\\link.exe' failed with exit status 1120
Seems that there is something wrong with the static links.
I tried implementing my own solution, but I had an error when opening the stream: Invalid number of channels (even though I was using the correct number).
When I tried selecting my speakers (any kind) as the device in the echo example, the programs says that the selection is input and does not support loopback mode.
I'm running the example on a Windows machine. How can I capture computer audio going through a given output device?
Has anyone been able to get this to work on Python 3.5 (Windows 64-bit)? I got it to compile with Cygwin however that currently only supports up to Python 3.4. On 3.5 when I run setup.py I get an error while building '_portaudio'.
I'm trying to install this fork to use the loopback adapter, and after installing using the .msi installer, when I try to import pyaudio, I get the following from python:
ModuleNotFoundError: No module named '_portaudio'
I made a post on here (stackoverflow) talking about this problem. Basically stream.read is "getting stuck" while stream is open, thus not returning any data. However, when the stream stops, it returns old data
Link :--- https://www.youtube.com/watch?v=XksalwvNCkU
This is a simple video for installing pyaudio and portsound for Python 3.7
I install cygwin
then I run Cygwin64 Terminal,change directory to "pyaudio_portaudio-master\pyaudio\portaudio-v19"
type "make"
then change directory to "pyaudio_portaudio-master\pyaudio"
type "python setup.py install --static-link"
and these error occur:
$ python setup.py install --static-link
running install
running bdist_egg
running egg_info
writing src\PyAudio.egg-info\PKG-INFO
writing top-level names to src\PyAudio.egg-info\top_level.txt
writing dependency_links to src\PyAudio.egg-info\dependency_links.txt
reading manifest file 'src\PyAudio.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
warning: no files found matching '.py' under directory 'test'
warning: no files found matching '.c' under directory 'test'
warning: no directories found matching 'docs'
writing manifest file 'src\PyAudio.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
building '_portaudio' extension
C:\Users\GoTop\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -DMS_WIN64=1 -I./portaudio-v19\include/ -IE:\Python27\include -IE:\Python27\PC /Tcsrc/_portaudiomodule.c /Fobuild\temp.w in-amd64-2.7\Release\src/_portaudiomodule.obj
_portaudiomodule.c
e:\python27\include\pyconfig.h(142) : warning C4005: 'MS_WIN64' : macro redefinition
command-line arguments : see previous definition of 'MS_WIN64'
src/_portaudiomodule.c(46) : warning C4005: 'min' : macro redefinition
C:\Users\GoTop\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Include\stdlib.h(850) : see previous definition of 'min'
src/_portaudiomodule.c(1357) : error C2059: syntax error : '{'
src/_portaudiomodule.c(1357) : warning C4013: 'typeof' undefined; assuming extern returning int
src/_portaudiomodule.c(1357) : error C2146: syntax error : missing ';' before identifier '_b'
src/_portaudiomodule.c(1357) : error C2065: '_b' : undeclared identifier
src/_portaudiomodule.c(1357) : error C2065: '_a' : undeclared identifier
src/_portaudiomodule.c(1357) : error C2065: '_b' : undeclared identifier
src/_portaudiomodule.c(1357) : error C2065: '_a' : undeclared identifier
src/_portaudiomodule.c(1357) : error C2065: '_b' : undeclared identifier
src/_portaudiomodule.c(1357) : error C2059: syntax error : ')'
src/_portaudiomodule.c(1357) : error C2059: syntax error : ')'
src/_portaudiomodule.c(1360) : warning C4018: '<' : signed/unsigned mismatch
src/_portaudiomodule.c(1361) : error C2065: 'output_data' : undeclared identifier
src/_portaudiomodule.c(1361) : warning C4022: 'memset' : pointer mismatch for actual parameter 1
src/_portaudiomodule.c(1367) : error C2143: syntax error : missing '{' before ':'
src/_portaudiomodule.c(1367) : error C2059: syntax error : ':'
src/_portaudiomodule.c(1374) : error C2059: syntax error : 'do'
src/_portaudiomodule.c(1374) : error C2059: syntax error : 'while'
src/_portaudiomodule.c(1375) : error C2059: syntax error : 'do'
src/_portaudiomodule.c(1375) : error C2059: syntax error : 'while'
src/_portaudiomodule.c(1376) : error C2059: syntax error : 'do'
src/_portaudiomodule.c(1376) : error C2059: syntax error : 'while'
src/_portaudiomodule.c(1378) : error C2371: 'PyGILState_Release' : redefinition; different basic types
e:\python27\include\pystate.h(170) : see declaration of 'PyGILState_Release'
src/_portaudiomodule.c(1379) : error C2059: syntax error : 'return'
src/_portaudiomodule.c(1380) : error C2059: syntax error : '}'
error: command '"C:\Users\GoTop\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe"' failed wi th exit status 2
Hi intxcc,
PyAudio-0.2.11.cygwin-2.10.0-x86_64-py3.6.whl is not a supported wheel on this Win10 (64bit).
I think PyAudio-0.2.11-cp36-cp36m-win_amd64.whl might work.
I am working on a small project that involves non-blocking stream reading. When I use the stream_callback property, the python script freezes for a second before exiting without any errors. Here is my code snippet where this issue is happening:
import pyaudio
# Setup settings
CHUNK = 1024 * 4
FORMAT = pyaudio.paInt16
CHANNELS = 1
p = pyaudio.PyAudio()
device_id = 6
print("Default device is " + str(device_id))
device_info = p.get_device_info_by_index(device_id)
def non_blocking_stream_read(in_data, frame_count, time_info, status):
print("Non-blocking func ran!")
return in_data, pyaudio.paContinue
print("Creating stream")
stream = p.open(format = FORMAT,
channels = CHANNELS,
rate = int(device_info["defaultSampleRate"]),
input = True,
frames_per_buffer = CHUNK,
input_device_index = device_info["index"],
stream_callback=non_blocking_stream_read,
as_loopback = True)
stream.start_stream()
print("Stream created!")
input("Press any key to continue...")
The only output I get is:
Default device is 6
Creating stream
Stream created!
Press any key to continue...
PS C:\Users\$USER\Desktop\Python Audio Testing>
Does anyone know if this kind of usage is possible? Any insight is appreciated.
NOTE: The program should have paused on the input function call, I did not press enter.
Edit: When switching the device to a input audio device and removing as_loopback, this script works fine.
Is it possible?
Man, It's not working
I am using visual studio 2019 on 64 bit machine, and followed your all the steps perfectly but still it didn't worked out. Sharing some details kindly preview and help!
Error Code on Administrator Command Prompt
C:\Windows\system32>cd C:\Users\Harsh Jaiswal\Downloads\pyaudio_portaudio-master\pyaudio
C:\Users\Harsh Jaiswal\Downloads\pyaudio_portaudio-master\pyaudio>python.exe .\setup.py install --static-link
running install
running bdist_egg
running egg_info
creating src\PyAudio.egg-info
writing src\PyAudio.egg-info\PKG-INFO
writing dependency_links to src\PyAudio.egg-info\dependency_links.txt
writing top-level names to src\PyAudio.egg-info\top_level.txt
writing manifest file 'src\PyAudio.egg-info\SOURCES.txt'
reading manifest file 'src\PyAudio.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'src\PyAudio.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib.win-amd64-3.7
copying src\pyaudio.py -> build\lib.win-amd64-3.7
running build_ext
building '_portaudio' extension
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
creating build\temp.win-amd64-3.7\Release\src
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -DMS_WIN64=1 -I./portaudio-v19\include/ "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /Tcsrc/_portaudiomodule.c /Fobuild\temp.win-amd64-3.7\Release\src/_portaudiomodule.obj
_portaudiomodule.c
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\include\pyconfig.h(117): warning C4005: 'MS_WIN64': macro redefinition
src/_portaudiomodule.c: note: see previous definition of 'MS_WIN64'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /nodefaultlib:libucrt.lib ucrt.lib /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\libs" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\PCbuild\amd64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.18362.0\um\x64" winmm.lib ole32.lib uuid.lib advapi32.lib user32.lib /EXPORT:PyInit__portaudio build\temp.win-amd64-3.7\Release\src/_portaudiomodule.obj /OUT:build\lib.win-amd64-3.7_portaudio.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\src_portaudio.cp37-win_amd64.lib ./portaudio-v19\build/msvc/x64/Release/portaudio.lib
LINK : fatal error LNK1181: cannot open input file '.\portaudio-v19\build\msvc\x64\Release\portaudio.lib'
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.22.27905\bin\HostX86\x64\link.exe' failed with exit status 1181
the portaudio.dll genration worked well as you said it said not existed.
installing pyaudio and portaudio errored.
Using Python 3.7 in Visual Studio
Right now, Im looping through every audio device, comparing the name of the default output device to the one at the index, checking if they match, and then checking if the one at index is using WASAPI. If it does, then I set it as the default output device to make sure the device can be used with Loopback in my program. Its quite the janky solution, and doesn't seem to work on different pc's than my own, so I'd like to make it as flexible as possible when it comes to working on other pcs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.