How to play a background audio?

0

I'm doing a python program that runs within an infinite loop ..

Under certain conditions I need to play an audio, but I can not wait for the audio to finish to continue the process. I thought of something async, that is, while I'm running the process (loop) a thread is created to play the audio while everything else continues. Well I'm talking about thinking of my development language (C #) in Python I do not know how to do

I tried with subprocess but it basically just opens an AVL of life and plays it, and even then it is not an unattended play

while True:
    time.sleep(1)
    if condicao1 > condicao2:
        PlayAudio ##toca o audio e continua
        #Gravalog()
    
asked by anonymous 31.05.2018 / 23:41

1 answer

2

Play Audio as a parallel task using Thread.

import threading

def audio():
    PlayAudio ##toca o audio e continua

while True:
    time.sleep(1)
    if condicao1 > condicao2:
        threading.Thread(target=audio).start() # Executa o Audio em uma Tarefa Paralela.
        #Gravalog()
    
01.06.2018 / 01:02