示例#1
0
文件: play.py 项目: heramareh/test
def print_lrc(mixer, lrc_d, color, wholetime):
    mixer.play()
    # 防止开头歌词来不及播放
    mixer.pause()
    time.sleep(0.001)
    mixer.play()
    while 1:
        # 截取到0.1s精度,降低cpu占用
        t = mixer.seconds() / 100 * 100
        sys.stdout.write('[' +
                         time.strftime("%M:%S", time.localtime(t / 1000)) +
                         '/' +
                         time.strftime("%M:%S", time.localtime(wholetime)) +
                         '] ')
        if t in lrc_d:
            sys.stdout.write(color + lrc_d[t] + '\033[0m')
            sys.stdout.flush()
            # 向后清除
            sys.stdout.write("\033[K")
        else:
            sys.stdout.flush()
            # 向后清除
            # sys.stdout.write("\033[K")
        sys.stdout.write('\r')
        # 播放停止时退出
        if t < 0:
            sys.exit(0)
        # 0.05s循环
        time.sleep(0.05)
示例#2
0
 def play(self, url):
     if self.type == 'mp3':
         mp3 = Mp3AudioPlayer('Judy', 'Loving you.mp3')
         mp3.play(url)
     elif self.type == 'wav':
         wav = WavAudioPlayer('Candy', 'Hating you.mp3')
         wav.play(url)
     else:
         print "failed to play the file"
示例#3
0
def play_music():
    pm.init()
    pm.music.load(random.choice(soundfiles))
    pm.play()
示例#4
0
def talk_en(words):
    tts = gTTS(text=words, lang='en')
    tts.save('sample_1.mp3')
    mixer.init()
    mixer.load('sample_1.mp3')
    mixer.play()