Проблема Alsa с Python

У меня есть программа, написанная на Python, которая вызывает другую программу, которая записывает звук и ищет триггер в звуке. Когда я вызываю другую программу из командной строки, она работает нормально, но при вызове в моей программе на Python выдает ошибку на некоторых компьютерах. Я использую pipewire в Ubuntu. Микрофон представляет собой bluetooth-гарнитуру. Есть ли у вас какие-либо предложения, где это можно отладить?

Ошибка:

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

0 ответов

Другие вопросы по тегам