How to play a background audio?

Asked

Viewed 38 times

0

I’m making a python program that runs inside an infinite loop..

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

I tried with subprocess but it basically just opens an AVL of life and touches it, and yet it’s not an unattended play

while True:
    time.sleep(1)
    if condicao1 > condicao2:
        PlayAudio ##toca o audio e continua
        #Gravalog()

1 answer

2

Play Audio as a side 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()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.