我有一个用 Python 编写的程序,它调用另一个正在录制音频并在音频中寻找触发器的程序。当我从命令行调用另一个程序时,它工作正常,但是在我的 python 程序中调用时,它在某些计算机上出现错误。我在 Ubuntu 上使用 pipewire。麦克风是蓝牙耳机。您对在哪里进行调试有什么建议吗?
错误是:
arecord: main:852: audio open error: No such file or directory
以下是相关的代码片段:
while not Stop_Program:
Trigger_Cmd = runcmd(Config_info['Trigger'])
for cmd_Log in Trigger_Cmd.getline():
print("cmd_Log: ", cmd_Log)
class runcmd:
def fillQueue(self,command):
self.process = subprocess.Popen("exec " + command, stdout=PIPE, stderr=PIPE, shell=True)
while self.process.poll() == None:
# poll() == None --> process is still running
line = self.process.stdout.readline().rstrip()
if len(line) > 0:
self.CmdQueue.put(line)
#else:
# print('No output')
time.sleep(0.01)
(results, errors) = self.process.communicate()
print("Command finished", errors)
# Code Below used to check command is valid, pass back invalid to caller
if len(errors) > 0:
self.CmdQueue.put(None)
time.sleep(1)
self.run = False
def __init__(self,command):
self.run = True
self.CmdQueue = queue.Queue()
#not sure if the exec will work...
self.Line_Thread = threading.Thread(target=self.fillQueue ,args=(command,))
self.Line_Thread.daemon = True
self.Line_Thread.start()
def getline(self):
while self.run:
if not self.CmdQueue.empty():
linedata = self.CmdQueue.get(True) #Blocking
yield linedata
else:
time.sleep(0.01)
#No longer running, stop process.
self.process.kill()
#print("End getline")