How to play and pause a .wav audio thru python?

Viewed 61

I want to play and pause an audio with play time decided by user. It should be automated. Play time should be as per user specified time(for eg. 2 minutes- means 2 minutes play the audio, then i am doing some operation, then i want to resume the audio playing for next 2min and so on and once end of audio is reached-it should stop playing and exit). How can this be achieved?

pygame.init()
MUSIC_END = pygame.USEREVENT+1
pygame.mixer.music.set_endevent(MUSIC_END)

pygame.mixer.music.load('long_audio_speechdB_75_SNR_20_11-02-2020-15-23-33.wav')
pygame.mixer.music.play()
print("bleeee1")
running = True
print("info sent")
print("data start sent")
f = 0
while running:
print("Vll")
timer = pygame.mixer.music.get_pos()
print(timer)      
for event in pygame.event.get():
    print("event:{}".format(event))
    if event.type==MUSIC_END:
        print("music end")
        running = False
if timer==100:
    print("Pause...")
    timer=0
    pygame.mixer.music.pause()
    time.sleep(5)
    #print("stop sent")
    #print("receive frm RX")
    #timer=0  
print("next play")      
pygame.mixer.music.unpause()

pygame.quit()

This pauses the audio only when timer = 100, how to make pause for EVERY 2 minutes and not the first 2 minutes

0 Answers
Related