简体   繁体   中英

Python pyglet repeats playing the audio non stop

The play sound (should be a short beep) doesn't stop. I made a short test case below. The IDE is VS2019.

import cv2
import numpy as np
import dlib
from math import hypot
import pyglet
import time

# Load sounds
sound = pyglet.media.load("sound.wav", streaming=False)
left_sound = pyglet.media.load("left.wav", streaming=False)
right_sound = pyglet.media.load("right.wav", streaming=False)
sound.play()
while True:
    print("***")

How can I make it play once the beep? (without time measuring)

Instead of while True loop use pyglet.app.run() :

import pyglet

sound = pyglet.resource.media('sound.wav')
sound.play()

pyglet.app.run()

See pyglet documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM