示例#1
0
def main(myWin, test_num, result, error):
    msg1 = visual.TextStim(myWin, font='ヒラギノ角ゴシック W5', color='Black')
    msg2 = visual.TextStim(myWin, font='ヒラギノ角ゴシック W5', color='Black')
    msg1.setText('結果発表')
    msg1.pos = (0, 0.6)
    msg2.height = (0.25)
    msg1.draw()
    myWin.flip()
    pygame.mixer.init()
    pygame.mixer.music.load(announce)
    pygame.mixer.music.play(1)
    time.sleep(3.5)
    pygame.mixer.music.stop()
    time.sleep(0.01)

    grade = [[0.225, 0.242, 0.263],\
             [0.265, 0.297, 0.350],\
             [0.288, 0.331, 0.376],\
             [0.306, 0.340, 0.373]]

    if error == True:
        msg2.setText('ミスが多すぎました')
        msg1.draw()
        msg2.draw()
        myWin.flip()
        pygame.mixer.init()
        pygame.mixer.music.load(tin)
        wait = mp3(tin).info.length
        pygame.mixer.music.play(1)
        time.sleep(wait)
        pygame.mixer.music.stop()
        time.sleep(1)

    else:
        if mean(result) < grade[test_num - 1][0]:
            msg2.setText('お前がNO.1だ!!')
            index = 0
        elif mean(result) < grade[test_num - 1][1]:
            msg2.setText('グレイト!')
            index = 1
        elif mean(result) < grade[test_num - 1][2]:
            msg2.setText('合格です!')
            index = 2
        else:
            msg2.setText('残念…\n次は頑張ろう')
            index = 3

        msg1.draw()
        msg2.draw()
        myWin.flip()
        pygame.mixer.init()
        pygame.mixer.music.load(voice[index])
        wait = mp3(voice[index]).info.length
        pygame.mixer.music.play(1)
        time.sleep(wait)
        pygame.mixer.music.stop()
        time.sleep(1)
示例#2
0
def detected_callback():
    pygame.mixer.init()

    #1
    osc_method("/state_receive", handlerfunction)
    state = osc_message
    msg = oscbuildparse.OSCMessage("/event_state", None, [state])
    osc_send(msg, "input_state")
    osc_process()

    pygame.mixer.music.load(filename1)
    mp3_length = mp3(filename1).info.length
    pygame.mixer.music.play(1)
    sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()

    #2
    osc_method("/state_receive", handlerfunction)
    state = osc_message
    msg = oscbuildparse.OSCMessage("/event_state", None, [state])
    osc_send(msg, "input_state")
    osc_process()

    pygame.mixer.music.load(filename2)
    mp3_length = mp3(filename2).info.length
    pygame.mixer.music.play(1)
    sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()

    #3
    osc_method("/state_receive", handlerfunction)
    state = osc_message
    msg = oscbuildparse.OSCMessage("/event_state", None, [state])
    osc_send(msg, "input_state")
    osc_process()

    pygame.mixer.music.load(filename3)
    mp3_length = mp3(filename3).info.length
    pygame.mixer.music.play(1)
    sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()

    #4
    osc_method("/state_receive", handlerfunction)
    state = osc_message
    msg = oscbuildparse.OSCMessage("/event_state", None, [state])
    osc_send(msg, "input_state")
    osc_process()

    pygame.mixer.music.load(filename4)
    mp3_length = mp3(filename4).info.length
    pygame.mixer.music.play(1)
    sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()
示例#3
0
def jud_text(tex, numbe, new_numbe):

    if (tex == word[numbe][5]):
        score[numbe] += 1
        print('あなたは{}回目に正解しました。'.format(score[numbe]))
        new_score[new_numbe] = score[numbe]
        return 0
    elif (tex != word[numbe][5]):
        score[numbe] += 1
        print("ちゃんと発音してね")
        while True:
            if msvcrt.kbhit():
                kb = msvcrt.getch()
                if kb.decode() == 'a':
                    pygame.mixer.init()
                    pygame.mixer.music.load(word[numbe][1])
                    mp3_length = mp3(word[numbe][1]).info.length
                    pygame.mixer.music.play(1)
                    time.sleep(mp3_length + 0.25)
                    pygame.mixer.music.stop()
                elif kb.decode() == 'b':
                    return 1
                elif kb.decode() == 'c':
                    score[numbe] = 0
                    new_score[new_numbe] = score[numbe]
                    return 0
示例#4
0
 def __play_sound(self, path) :
     pygame.mixer.init()
     pygame.mixer.music.load(path)
     mp3_length = mp3(path).info.length
     pygame.mixer.music.play(1)
     time.sleep(mp3_length + 0.25)
     pygame.mixer.music.stop()
def mp3play(filename):
    """
    mp3データを音声再生する
    @param  filename 再生するmp3データ
    @return なし
    """
    from mutagen.mp3 import MP3 as mp3
    import pygame
    import time

    try:
        pygame.mixer.init()
        """
        pygame.mixer.music.load(filename)
        mp3_length = mp3(filename).info.length
        pygame.mixer.music.play(1)
        time.sleep(mp3_length + 0.25)
        pygame.mixer.music.stop()
        """

        pygame.mixer.music.load(filename)
        mp3_length = mp3(filename).info.length
        pygame.mixer.music.play(1)
        # pygame.mixer.music.play(-1)
        #time.sleep(mp3_length + 0.25)
        #pygame.mixer.music.stop()

        while True:
            pygame.time.delay(1)

    except Exception as e:
        traceback.print_exc()
        sys.exit()
示例#6
0
def play_mp3(file_path):
    pygame.mixer.init()
    pygame.mixer.music.load(file_path)
    mp3_len = mp3(file_path).info.length
    pygame.mixer.music.play(1)
    time.sleep(mp3_len + 0.1)
    pygame.mixer.music.stop()
def play(filename):  # MP3を再生,3回再生
    pygame.mixer.init()
    pygame.mixer.music.load(filename)  # 音源読み込み
    mp3_length = mp3(filename).info.length  # 音源の長さ取得
    pygame.mixer.music.play(3)  # 再生回数指定
    time.sleep(mp3_length * 3 + 0.25)  # 再生回数指定時長さ変更,再生開始後音源の長さ待機(0.25s誤差解消)
    pygame.mixer.music.stop()  # 再生停止
示例#8
0
def playVoice(filename):
    pygame.mixer.init()
    pygame.mixer.music.load(filename)
    mp3_length = mp3(filename).info.length
    pygame.mixer.music.play(1)
    time.sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()
    return
示例#9
0
def playsound():
    filename = "japanese-chess-piece1.mp3"  # 再生したいmp3ファイル
    pygame.mixer.init()
    pygame.mixer.music.load(filename)  # 音源を読み込み
    mp3_length = mp3(filename).info.length  # 音源の長さ取得
    pygame.mixer.music.play(1)  # 再生開始。1の部分を変えるとn回再生(その場合は次の行の秒数も×nすること)
    time.sleep(mp3_length + 0.25)  # 再生開始後、音源の長さだけ待つ(0.25待つのは誤差解消)
    pygame.mixer.music.stop()  # 音源の長さ待ったら再生停止
示例#10
0
 def sound_dev_mp3(self, file_name):   
     filename = self.dev_path + file_name #再生したいmp3ファイル
     pygame.mixer.init()
     pygame.mixer.music.load(filename) #音源を読み込み
     mp3_length = mp3(filename).info.length #音源の長さ取得
     pygame.mixer.music.play(1) #再生開始。1の部分を変えるとn回再生(その場合は次の行の秒数も×nすること)
     time.sleep(mp3_length + 0.25) #再生開始後、音源の長さだけ待つ(0.25待つのは誤差解消)
     pygame.mixer.music.stop() #音源の長さ待ったら再生停止
示例#11
0
def mp3_voice(mp3_file_path):
    mp3_file = mp3_file_path
    pygame.mixer.init()
    pygame.mixer.music.load(mp3_file)
    mp3_length = mp3(mp3_file).info.length
    pygame.mixer.music.play(1)
    time.sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()
示例#12
0
 def sound2(self):
     filename = "darts_award_sound.mp3"  # 再生したいmp3ファイル
     pygame.mixer.init()
     pygame.mixer.music.load(filename)  # 音源を読み込み
     mp3_length = mp3(filename).info.length  # 音源の長さ取得
     pygame.mixer.music.play(1)  # 再生開始。1の部分を変えるとn回再生(その場合は次の行の秒数も×nすること)
     time.sleep(mp3_length + 0.25)  # 再生開始後、音源の長さだけ待つ(0.25待つのは誤差解消)
     pygame.mixer.music.stop()  # 音源の長さ待ったら再生停止
示例#13
0
def bell():
    filename = 'bell.mp3'
    pygame.mixer.init()
    pygame.mixer.music.load(filename)
    mp3_length = mp3(filename).info.length
    pygame.mixer.music.play(1)
    time.sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()
示例#14
0
def play():
    filename = random.choice(ENGLISH_WORDS_LIST)
    pygame.mixer.init()
    pygame.mixer.music.load(filename)
    mp3_length = mp3(filename).info.length
    pygame.mixer.music.play(1)
    time.sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()
    pygame.mixer.quit()
示例#15
0
def readmp3():
    filename = 'You Suffer.mp3'

    pygame.mixer.init()
    pygame.mixer.music.load(filename)
    mp3_length = mp3(filename).info.length
    pygame.mixer.music.play(1)
    time.sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()
示例#16
0
def play_mp3():
    global cnt
    filename = "{任意の保存先パス}/gousei" + str(cnt) + ".mp3"  #再生したいmp3ファイル
    pygame.mixer.init()
    pygame.mixer.music.load(filename)  # 音源を読み込み
    mp3_length = mp3(filename).info.length  # 音源の長さ取得
    pygame.mixer.music.play(1)  # 再生開始。1の部分を変えるとn回再生(その場合は次の行の秒数も×nすること)
    time.sleep(mp3_length + 0.25)  # 再生開始後、音源の長さだけ待つ(0.25待つのは誤差解消)
    pygame.mixer.music.stop()  # 音源の長さ待ったら再生停止
示例#17
0
def voice():
    filename = 'Thank you.mp3' #再生したいmp3ファイル
    pygame.mixer.init()
    pygame.mixer.music.load(filename) #音源を読み込み
    mp3_length = mp3(filename).info.length #音源の長さ取得
    pygame.mixer.music.play(1) #再生開始。1の部分を変えるとn回再生(その場合は次の行の秒数も×nすること)
    time.sleep(mp3_length + 0.25) #再生開始後、音源の長さだけ待つ(0.25待つのは誤差解消)
    pygame.mixer.music.stop() #音源の長さ待ったら再生停
    return render_template('tv_on.html')
示例#18
0
def rep_mp3(tgt_word):  # 音声を再生

    filename = 'C:/Users/fumin/OneDrive/デスクトップ/English_words/' + tgt_word + '.mp3'  # 再生したいmp3ファイル
    pygame.mixer.init()
    pygame.mixer.music.load(filename)  # 音源を読み込み
    mp3_length = mp3(filename).info.length  # 音源の長さ取得
    pygame.mixer.music.play(1)  # 再生開始。1の部分を変えるとn回再生(その場合は次の行の秒数も×nすること)
    time.sleep(mp3_length + 0.25)  # 再生開始後、音源の長さだけ待つ(0.25待つのは誤差解消)
    pygame.mixer.music.stop()  # 音源の長さ待ったら再生停止
示例#19
0
def play_music():
    music_filename = "firefly.mp3"
    pygame.mixer.init()
    pygame.mixer.music.load(music_filename)
    mp3_length = mp3(music_filename).info.length
    pygame.mixer.music.play(1)
    time.sleep(10)
    pygame.mixer.music.stop()
    global Flag
    Flag = False
示例#20
0
 def generate_playlist(self):
     for i in os.listdir(self.path):
         if i.endswith('.mp3'):
             songg = mp3(os.path.realpath(os.path.join(self.path, i)))
             self.songs.append(Song(
                 title=songg['TIT2'][0], artist=songg['TPE1'][0], album=songg[
                     'TALB'][0], length=round(songg.info.length, 2), filename=songg.filename))
         else:
             pass
     return self.songs
示例#21
0
def btn_click():
    global a, b, c, j, count, button, lang, label, question
    print(b)
    if answer[int(j)] == b:
        # 正解の場合
        tk.Label(root, text="正解!", justify=tk.LEFT, padx=20).pack()
        filename = 'bestselect.mp3'
        pygame.mixer.init()
        pygame.mixer.music.load(filename)
        mp3_length = mp3(filename).info.length
        pygame.mixer.music.play(1)
        j += 1
        queston_box(int(j))
        a += 1
        count += 1
        question_select(languages2[0], languages2[1], languages2[2],
                        languages2[3], answer[int(j)], question[int(j)])
    else:
        #不正解の場合
        tk.Label(root, text="不正解", justify=tk.LEFT, padx=20).pack()
        filename = 'badselect.mp3'
        pygame.mixer.init()
        pygame.mixer.music.load(filename)
        mp3_length = mp3(filename).info.length
        pygame.mixer.music.play(1)
        j += 1
        count += 1
        queston_box(int(j))
        question_select(languages2[0], languages2[1], languages2[2],
                        languages2[3], answer[int(j)], question[int(j)])
    if int(count) == 4:
        sub_win = tk.Toplevel(root)
        sub_win.title(u"結果")
        label2 = tk.Label(sub_win, text="あなたの正解数は" + str(a) + "です")
        esc_button = tk.Button(sub_win,
                               text="閉じる",
                               command=sys_btn,
                               width=15,
                               bg="#ff00ff",
                               fg="white")
        label2.pack()
        esc_button.pack()
示例#22
0
def up_timer(secs):
    for i in range(0, secs):
        print(i)
        sleep(1)
    filename = './one05.mp3'  #再生したいmp3ファイル
    pygame.mixer.init()
    pygame.mixer.music.load(filename)
    mp3_length = mp3(filename).info.length
    pygame.mixer.music.play(1)
    sleep(mp3_length + 0.25)
    pygame.mixer.music.stop()
def playMusic(filename, playTime=None):
    filename = music_path + filename
    pygame.mixer.init()
    pygame.mixer.music.load(filename)  # 音源を読み込み
    mp3_length = mp3(filename).info.length  # 音源の長さ取得
    pygame.mixer.music.play(1)  # 再生開始。1の部分を変えるとn回再生(その場合は次の行の秒数も×nすること)
    if playTime is None:
        time.sleep(mp3_length + 0.25)
    else:
        time.sleep(1)  # 再生開始後、音源の長さだけ待つ(0.25待つのは誤差解消)
    pygame.mixer.music.stop()  # 音源の長さ待ったら再生停止
示例#24
0
def soundon(new_flag:int):
    if new_flag != 3:
        filename = {0:'red2.mp3', 1:'green2.mp3', 2:'idk.mp3'}
        pygame.mixer.init()
        pygame.mixer.music.load(filename[new_flag])
        mp3_length = mp3(filename[new_flag]).info.length
        pygame.mixer.music.play(1)
        time.sleep(mp3_length+0.25)
        pygame.mixer.music.stop()
        sys.exit()
    else:
        pygame.mixer.music.stop()
示例#25
0
    def __init__(self):
        #init publisher
        self.resetContainer()
        rospy.init_node('logger', anonymous=True)
        self.absoluteSaveFolderName = "/home/ytnpc2017c/catkin_ws/src/wagon_logging/logData/"

        self.soundName = '/home/ytnpc2017c/catkin_ws/src/wagon_logging/sound/se.mp3'  #再生したいmp3ファイル
        pygame.mixer.init()
        pygame.mixer.music.load(self.soundName)  #音源を読み込み
        self.soundlength = mp3(self.soundName).info.length  #音源の長さ取得

        print("init")
示例#26
0
def play_music():
    #music_filename = "firefly.mp3"
    music_filename = "zinnzya.mp3"
    pygame.mixer.init()
    pygame.mixer.music.load(music_filename)
    #pygame.mixer.music.set_volume()
    mp3_length = mp3(music_filename).info.length
    pygame.mixer.music.play(1)
    time.sleep(mp3_length + 2)
    pygame.mixer.music.stop()
    global Flag
    Flag = False
示例#27
0
def play_voice():
    print('発声開始')
    filename = 'data/tmp_voice.mp3'
    with open(filename) as f:
        m = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
    pygame.mixer.init(44100)
    pygame.mixer.music.load(m)  # 音源を読み込み # pygameは音声ファイルをcloseしないバグがあるので対応
    mp3_length = mp3(filename).info.length  # 音源の長さ取得
    pygame.mixer.music.play(1)  # 再生開始。1の部分を変えるとn回再生(その場合は次の行の秒数も×nすること)
    time.sleep(mp3_length)  # 再生開始後、音源の長さだけ待つ(0.25待つと誤差解消できたりする)
    pygame.mixer.music.stop()  # 音源の長さ待ったら再生停止
    m.close()
示例#28
0
 def playback(self):
     while not rospy.is_shutdown() and self.play_flg is False:
         rospy.loginfo('Waiting for filename')
         rospy.sleep(1.0)
     self.play_flg = True
     # 再生処理
     filename = '/home/issei/catkin_ws/src/mimi_bgm/mp3_file/ElectrricalParade.mp3'
     pygame.mixer.init()
     pygame.mixer.music.set_volume(0.5)
     pygame.mixer.music.load(filename)
     mp3_length = mp3(filename).info.length
     pygame.mixer.music.play(1)
     rospy.sleep(mp3_length)
     pygame.mixer.music.fedeout(5.0)
示例#29
0
 def __init__(self, info):
     from mutagen.mp3 import MP3 as mp3
     from mutagen.easyid3 import EasyID3
     from mutagen.id3 import ID3
     EasyID3.RegisterTextKey('description', "COMM")
     p = path + name
     audio = mp3(p, ID3=EasyID3)
     for key, value in info.items():
         try:
             audio[key] = value
         except:
             pass
     audio.save()
     self.audio = ID3(p)
     self.id = info['description']
示例#30
0
def string(string: str):
    """Speak string by gTTS
    Arg:
        string: speak this string.
    """
    tts = gTTS(text=string, lang='ja')
    tts.save(BUFFER_FILE_NAME)  # buffer file(MP3)
    pygame.mixer.init()
    pygame.mixer.music.load(BUFFER_FILE_NAME)
    # get buffer file(MP3)'s length (second)
    mp3_length = mp3(BUFFER_FILE_NAME).info.length
    pygame.mixer.music.play(1)  # play only one time
    time.sleep(mp3_length + 0.25)  # continue play
    pygame.mixer.music.stop()
    os.remove(BUFFER_FILE_NAME)  # delete buffer file(MP3)
示例#31
0
def playList(number):
    # list player
    # Input: List ID in TrackLists[], Output: Sound
    global curList
    id = int(number) - 1
    cur_list = TrackLists[id]
    print(" - Playing the list:" + str(cur_list))
    curList = cur_list
    for track in cur_list:
        audio = mp3(track)
        length = audio.info.length + 3.0
        player.music.load(track)
        player.music.play(1)
        minutes = int(length) / 60
        print(" - Playing: " + track + "  Lenght:" + str(minutes) +
              " minutes.")
        sleep(length)
示例#32
0
def mp3parse(listob):
	for song in sorted(listob):
		#modify indiced if just using a list
		if (song[1])[1]==".mp3":
			smp3=mp3(song[2])
			s=(song[1])[0]
			artist,album,title = (smp3.get('TPE1'),smp3.get('TALB'),smp3.get('TIT2'))
			# weeds out files with incomplete metadata
			if not title:
				#create function to assign metadata to file based info from filename
				#?move files to dir for orphaned or files with no metadata? 
		 		pass
		 		#print "no title metadata for: %s" % (song[1])[0]
			# elif not album:
			# 	#move file to orphaned file dir
			#  	continue
			elif not artist:
				#move file to orphaned file dir
				pass
			else:
			# 	#prints pretty formatted metadata of mp3 files (temporary. Just to see if working)
			# 	#yield "%s - %s - %s \n %s \n" % (artist,album,songname,s)
				yield artist,s
try: # a few files are m4a, not mp3
    pygame.mixer.music.load(songs[cursong])
except: # file cannot be played - this shouldn't happen. ever.
    log.error("Could not play song:", songs[cursong])
try:
    albumart = mfile(songs[cursong]).tags["APIC:"].data
    with open("albumart.jpg", "wb") as img:
        img.write(albumart)
except:
    albumartf = open("albumart-placeholder.png", "rb")
    albumart = albumartf.read()
    albumartf.close()
    with open("albumart.jpg", "wb") as img:
        img.write(albumart)
if songs[cursong].endswith(".mp3"):
    tracklength = mp3(songs[cursong]).info.length
else:
    tracklength = None
metadata = id3(songs[cursong])
try:
    log.info("SONG #" + str(cursong) + " | Playing " + metadata['TIT2'].text[0]
             + " in " + metadata['TALB'].text[0] + " by "
             + metadata['TPE1'].text[0])
except:
    log.debug("Unable to get metadata for " + songs[cursong] + """.
Basing it off directory tree instead.""")
    log.info("SONG #" + str(cursong) + " | Playing "
             + songs[cursong].split("/")[3].split(".")[0] + " in "
             + songs[cursong].split("/")[2] + " by "
             + songs[cursong].split("/")[1])
pygame.mixer.music.play(0, st)
示例#34
0
    opt = str(arg[1])
    return opt[1]

#Checks if a flag was used
def checkflag():
    if '-' in arg[1]:
        x = 'y'
    else:
        x = 'n'
    return x

#Test/ show all metadata for a specified file
#usage: fdorg.py -t /path/to/file/
try:
    if arg[1] == '-t':
        x = mp3(arg[2])
        print x.get('TPE1') #This shows the artist of the specified file
        print x.get('TALB') #This shows the album of the specified file
        exit()
except IndexError:
    pass
#/Test

#Shows usage of fdorg.py if wrong number of arguments are given
if len(arg) < 3 or len(arg) > 4:
    print "usage: fdorg.py [OPTIONS] [/directory/to/sort] [/destination/folder]"
    exit()

#Runs fdorg.py assuming no flags
if checkflag() == 'n':
    metadata(arg[1],arg[2])