gpt4 book ai didi

python - 播放 WAV 歌曲时机器人不跳舞

转载 作者:太空宇宙 更新时间:2023-11-03 16:40:49 25 4
gpt4 key购买 nike

我正在开发一个项目,需要一组 Scribbler 2 在播放 wav 文件时跳舞并在文件末尾停止。

(这不是完整的代码,而是我测试如何做到这一点,以便我可以将其应用于更大的代码。)

from Myro import *
from winsound import*
from time import *

def playSong():
s=PlaySound('C:\Python34\cantHoldUs.wav',SND_FILENAME)
sleep(30)
s.PlaySound(None,SND_FILENAME)

while playSong()==True:
motors(-1,1)

歌曲播放并结束,但机器人没有移动。谁能告诉我怎么做?

最佳答案

我建议将您的代码重组为带有 While 循环的代码,因为它更干净且更易于控制:

from time import *

# Play the song
s=PlaySound('C:\Python34\cantHoldUs.wav',SND_FILENAME)

# Start the timer so we can identify when to stop
starttime = time()

# Use a while loop with a True statement until we decide to break it
while True:
# Make that robot dance!
motors(-1,1)

# Check the current time
stop_time = ((time() - starttime))

# Stop when 30 seconds is hit
if stop_time > 30:
s.PlaySound(None,SND_FILENAME)
break

sleep(1)

关于python - 播放 WAV 歌曲时机器人不跳舞,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36803843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com