|
音乐响起,同步ev3起舞蹈,采用 ev3dev python 编程,主要特点
1.可以在ev3主机上播放大段音乐,数分钟都没问题,得益于操作系统.
2.舞蹈与音乐同步,音乐声起,舞蹈开始,音乐结束,舞蹈终止,节奏符合,节奏感强.
需要改进的地方
1.节奏踏准还需要进一步精准.(如跳过序曲,踩准鼓点)
2.需要进一步分析音乐进而做出不同的动作.
3.马达运动数分钟后没回到原位,逐渐出先偏差,需要纠正.
-----------------源代码-----------------------------------
#!/usr/bin/env python3
from ev3dev2.motor import LargeMotor, OUTPUT_A, OUTPUT_B, SpeedPercent, MoveTank
from ev3dev2.sensor import INPUT_1
from ev3dev2.sensor.lego import TouchSensor
from ev3dev2.led import Leds
import time
import threading
from ev3dev2.sound import Sound
sound = Sound()
sound.set_volume(100)
def music():
print ('playing start time is:' + time.ctime())
sound.play_file('./toqiaqia.wav')
print ('playing over time is:' + time.ctime())
play_thread = threading.Thread(target=music)
m = LargeMotor(OUTPUT_A)
sound.speak('Ladys and gentlman ,Let me show u the dancing now!')
play_thread.setDaemon(True)
play_thread.start()
while play_thread.isAlive():
m.on_for_seconds(SpeedPercent(25), 0.33,brake=True)
time.sleep(0.13)
m.on_for_seconds(SpeedPercent(-25), 0.33,brake=True)
time.sleep(0.13)
print ("time Now:" + time.ctime())
sound.speak('playing over thank you!')
print ("all over time:" + time.ctime())
|
|