我正在尝试使用 applescript 来检索歌曲的 BPM 值。最终我想用一个游戏来实现它。这是我的代码:
import os
import time
import sys
def getBPM():
iTunesInstruct = """'
tell application "iTunes"
set k to get bpm of current track
end tell
return k
'"""
bpm = os.system('arch -i386 osascript -e ' + iTunesInstruct )
#bpm =90
bpm = int(bpm)
bpm = round(bpm)
if bpm > 250:
bpm = 200
return bpm
def getBeatSecond(bpm):
bps = float(bpm) / 60
#raw_input(bps)
return float(bps)
i = 0
beatMatch = True
while True:
beat = 1 / getBeatSecond(getBPM()) # BPS Beat divided by a second.
if beatMatch:
time.sleep(beat)
print beat
else:
raw_input('Go??')
i += 1
if i > 50:
break
但这似乎只工作一次......它得到了我正在听的歌曲的 BPM,看到它是 94,然后似乎在第二次迭代中它认为它是 0,然后它除以 0 并死亡。这是怎么回事?