每当我运行此代码时,我都听不到声音播放,甚至检查声音是否播放,然后继续进行下一行,但继续进行到下一行,并且不会发出噪音。这是代码:
import pygame
import time
import sys
pygame.init()
pygame.mixer.init()
binaryHighLow = "010111"
def check():
for x in binaryHighLow:
if x == "0" in binaryHighLow:
lowPitch = pygame.mixer.Sound("440Hz_44100Hz_16bit_05sec.wav")
lowPitch.play()
print("Low")
lowPitch.set_volume(1)
time.sleep(lowPitch.get_length())
elif x == "1" in binaryHighLow:
highPitch = pygame.mixer.Sound("5000hz.wav")
highPitch.play()
print("High")
highPitch.set_volume(1)
time.sleep(highPitch.get_length())
check()
关于我应该更改代码的任何建议吗?
答案 0 :(得分:0)
将pygame.init()
放在pygame.mixer.init()
之后。
例如:
pygame.mixer.init()
pygame.init()