如何使用 pyinstaller 和 Python 中的 sounddevice 模块获取工作 EXE 文件

How to get a working EXE file using pyinstaller with the sounddevice module in Python

很遗憾,pyinstaller 的声音设备模块有问题。

我写了下面的代码,但是当我使用pyinstaller 制作一个EXE 文件时,dist 文件夹中的EXE 文件不起作用。使用 pyinstaller 的制作过程成功完成,但 EXE 文件不起作用。

密码是:

import sounddevice as sd

fs=44100
duration =2 # seconds
print('Start')
myrecording = sd.rec(duration * fs, samplerate=fs,    channels=2,dtype='float64')
sd.wait()
print('play')
sd.play(myrecording, fs)
print('end')

问题可能是程序在您执行 sd.play() 后直接退出吗?

尝试用 sd.play(myrecording, fs, blocking=True)

替换该行

此外,sounddevice 不是一个完美的库,因此您需要做一些额外的调整才能使其正常工作:

在您的 EXE 所在的目录中,添加一个名为 _sounddevice_data 的目录并放置 this file into that folder (if you are using Python 64-bit) or this 一个(如果您使用的是 Python 32 位)。

尝试 运行 EXE,它应该可以工作!

希望对您有所帮助!

所选答案无效但有所帮助。

对我来说,可行的解决方案是添加 .exe 文件所在的 _sounddevice_data 文件夹,然后制作一个 portaudio-binaries 文件夹,最后将 libportaudio64bit.dll 放入最近创建的文件夹中。

希望对您有所帮助!