简体   繁体   English

如何在python中使用pyinstaller和sounddevice模块获取有效的EXE文件

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

Unfortunately pyinstaller has problem with the sounddevice module. 不幸的是pyinstaller的sounddevice模块有问题。

I wrote the code below, but when I make an EXE file using pyinstaller, the EXE file in the dist folder does not work. 我写了下面的代码,但是当我使用pyinstaller创建EXE文件时,dist文件夹中的EXE文件不起作用。 The making process using pyinstaller finishes successfully but the EXE file does not work. 使用pyinstaller的制作过程成功完成,但是EXE文件不起作用。

The code is: 代码是:

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')

Could the problem be that the program exits straight after you do sd.play() ? 问题可能出在您执行sd.play()之后程序立即退出吗?

Try replacing that line with sd.play(myrecording, fs, blocking=True) 尝试用sd.play(myrecording, fs, blocking=True)替换该行

Also, sounddevice is not a perfect library, so you need to do a bit of extra tweaking to make it work: 同样,声音设备也不是一个完美的库,因此您需要做一些额外的调整才能使其正常工作:

In your directory where your EXE is located, add a directory called _sounddevice_data and put this file into that folder (if you are using Python 64-bit) or this one (if you are using Python 32-bit). 在EXE所在的目录中,添加一个名为_sounddevice_data的目录,然后将此文件放入该文件夹(如果使用的是Python 64位)或文件夹(如果使用的是32位Python)。

Try running the EXE, it should work! 尝试运行EXE,它应该可以工作!

Hope this helps! 希望这可以帮助!

The selected answer didn't work but helped. 所选答案无效,但有所帮助。

For me, the working solution is to add _sounddevice_data folder where the .exe file is located then making a portaudio-binaries folder in it and finally putting libportaudio64bit.dll in the recently created folder. 对我来说,有效的解决方案是在.exe文件所在的位置添加_sounddevice_data文件夹,然后在其中创建一个portaudio-binaries文件夹,最后将libportaudio64bit.dll放入最近创建的文件夹中。

Hope it helps! 希望能帮助到你!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不使用pyinstaller的情况下为带有spacy的python程序创建exe文件? - How to create a exe file for python program with spacy without using pyinstaller? 如何使用pyinstaller将多个python文件编译成单个.exe文件 - How to compile multiple python files into single .exe file using pyinstaller 使用 python & kivy 在 pyinstaller 中生成的 exe 不起作用 - exe generated in pyinstaller using python & kivy is not working 如何停止执行使用 pyinstaller (windows) 创建的 python exe 文件 - How to stop executing the python exe file created using pyinstaller (windows) 如何在 python sounddevice 中使用 OutputStream 播放声音文件? - How to play a sound file using an OutputStream in python sounddevice? 当python脚本由专有模块组成时,PyInstaller如何管理创建和EXE文件? - How does PyInstaller manage to create and EXE file when the python script is consisted of proprietary module? Python 键盘模块在使用 pyinstaller 转换为 exe 时不捕获击键 - Python keyboard module not capturing keystrokes when coverted to exe using pyinstaller 当 python ttp 模块就位时使用 pyinstaller exe 时出错 - error using pyinstaller exe when python ttp module is in place Pyinstaller exe 文件不工作/打开 - Pyinstaller exe file is not working/opening Python 使用 pyinstaller 将文件转换为 exe 时语音识别不起作用 - Python Speech Recognition not working when the file is converted to exe with pyinstaller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM