手动歌词文件时段记录辅助程序

手动歌词文件时段记录辅助程序

制作一个小作品的辅助程序。

"""
   通过听音乐,当唱到下一句时手动单击记录时间
"""
import time
import turtle
from winsound import *

def record(x,y):
    times.append(time.time() - start_time)  # 当前行和上一行的播放时间
    
times = []

screen = turtle.getscreen()
#PlaySound('杨烁 - 童年.wav',9)
start_time = time.time()                     # 起始时间
screen.onclick(record)

# 下面的代码请先全部注释掉!
# times列表中的内容通过播放上面歌曲,单击而来。
times = [16.705955743789673, 19.76313042640686, 24.55040407180786, 27.298561334609985, 31.792818546295166, 34.48797273635864, 39.43625545501709, 43.30347681045532, 49.635838985443115, 52.271989822387695, 57.32727885246277, 60.07343602180481, 64.56769323348999, 67.20084381103516, 72.13212585449219, 76.03334903717041, 82.39871287345886, 84.93785834312439, 89.97814655303955, 92.7073028087616, 97.32856678962708, 99.665700674057, 104.95500326156616, 108.80622339248657, 115.46860456466675, 117.70173215866089, 122.75502133369446, 125.49917793273926, 129.94543266296387, 132.76859402656555, 137.49486446380615, 141.56909728050232, 147.80845427513123, 150.63361597061157, 155.49989414215088, 158.1810474395752, 162.61230087280273, 165.20244884490967, 170.27173900604248, 174.0939576625824, 177.4651505947113, 181.89640402793884]
fi = open('歌词.txt')                        # 这个文件是仅有歌词的
words = fi.readlines()
fi.close()

fo = open('歌词2.txt','w')                   # 这个文件把把时间段加上去
i = 0
for t in times:
    m = int(t//60)
    s = t%60
    hao = s - int(s)
    #print(m,int(s),round(100*hao))
    out = "[{:02}:{}.{}]".format(m,int(s),round(100*hao))
    fo.write(out+words[i])
    i += 1
fo.close()

李兴球

李兴球的博客是Python创意编程原创博客