does not play the audio file python in the while loop on orangepi 3b

  Kiến thức lập trình

I’m making a smart station on orangepi 3b on python3.10, put ubuntu 22.04 there, wrote the code, but the bad luck is that I don’t play the audio file in the while loop, although everything works fine on the PC, everything also works outside the loop

while True:
            data = stream.read(4096, exception_on_overflow=False)
            if rec.AcceptWaveform(data):
                result = json.loads(rec.Result())
                print(result)
                if result['text'].startswith('ник') and not is_recording:
                    print("Начало записи...")
                    outpute.wave('р.wav')
                    is_recording = True
                elif is_recording and result['text'] == '':
                    print("Завершение записи")
                    is_recording = False
                    break
                
            else:
                print(json.loads(rec.PartialResult()))
                if is_recording:
                    audio_data.extend(data)

The wave function

def wave(filename):
    data, fs = sf.read(filename, dtype='float32')
    sd.play(data, fs)
    time.sleep(len(data)/fs)
    sd.stop()

please help me, I have a project protection coming soon

LEAVE A COMMENT