Пример #1
0
    def selection_changed(self, widget):
        """单击词条时触发
        1、发音
        2、显示详细的解释
        """
        meaning_detail = self.builder.get_object("textview_word_detail")
        
        select_word = ''
        # 发音
        (tree_model, tree_iter) = widget.get_selected()
        if tree_iter :
            select_word = tree_model.get_value(tree_iter, COLUMN_WORD)
            if not self.is_mute:
                read(select_word)
            
            # print select_word
            # 寻找单词的完整解释、例句
            for word in self.words_list:
                if select_word == word['name']:
                    word_dic = word

            # print word_dic

            sentence_en_3 = [(word_dic['sen_en_1'], word_dic['sen_zh_1']),
                             (word_dic['sen_en_2'], word_dic['sen_zh_2']),
                             (word_dic['sen_en_3'], word_dic['sen_zh_3'])
                             ]
            if word_dic['sen_en_1']:
                sen_display = "\n例句与用法:"
                i = 1                     # 例句标号
                for item in sentence_en_3:
                    if item[0]:
                        sen_display +=  '\n\n' + str(i) + '. ' + item[0] + '\n    ' +  item[1]
                        i += 1
            else:
                sen_display = ''

            detial = gtk.TextBuffer()
            detial.set_text(
                word_dic['name']\
                + "\n" + '[' +  word_dic['pronounce'] + ']' \
                + "\n" + word_dic['meaning']
                + "\n" \
                + sen_display)

            meaning_detail.set_buffer(detial)
Пример #2
0
    def display_now_word(self):
        """显示新单词
        """
        self.now_word = self.words_typing.pop()

        if self.read_word:
            read(self.now_word['name'])

        self.character_pos = 0
        self.word_len = len(self.now_word['name'])

        self.entry_follow_input.set_text("") # 这个同样会引发insert-text事件

        self.label_follow_word.set_label(self.now_word['name'])
        self.label_follow_meaning.set_label(self.now_word['meaning'])
        self.entry_follow_input.set_max_length (self.word_len)

#        self.label_follow_times.set_label("第%d次" % self.now_times)
        self.progressbar_follow.set_text("第%d个 (共%d个)" % (self.now_turn, self.words_len))
        self.progressbar_follow.set_fraction(float(self.now_turn)/self.words_len)
Пример #3
0
    def __display_next_word(self):
        """显示下一单词
        """
        self.now = random.sample(self.pool, 1)[0]
        self.pool.remove(self.now)

        if self.read_word:
            read(self.now['name'])

        self.label_word.set_label(self.now['name'])
        self.progressbar_meaning.set_text("第%d个(共%d个)" % (len(self.passed_words) + 1, len(self.queue)))
        self.progressbar_meaning.set_fraction(float(len(self.passed_words)) / len(self.queue))

        answer_index = random.randint(0, 3)
        self.buttons[answer_index].set_label(self.now['meaning'].replace('\n', ' '))

        filling = random.sample(self.__withou_now_word(), 4)
        
        for button in self.buttons:
            if self.buttons.index(button) != answer_index:
                random_mean = filling[self.buttons.index(button)]
                button.set_label(random_mean['meaning'].replace('\n', ' '))
Пример #4
0
    def display_now_word(self):
        """显示新单词
        """
        self.now_word = self.words_typing.pop()

        if self.read_word:
            read(self.now_word['name'])

        self.character_pos = 0
        self.word_len = len(self.now_word['name'])

        self.entry_follow_input.set_text("")  # 这个同样会引发insert-text事件

        self.label_follow_word.set_label(self.now_word['name'])
        self.label_follow_meaning.set_label(self.now_word['meaning'])
        self.entry_follow_input.set_max_length(self.word_len)

        #        self.label_follow_times.set_label("第%d次" % self.now_times)
        self.progressbar_follow.set_text("第%d个 (共%d个)" %
                                         (self.now_turn, self.words_len))
        self.progressbar_follow.set_fraction(
            float(self.now_turn) / self.words_len)
Пример #5
0
duration = 2
Fe=44100
frame_size = duration*Fe//8192*8192
mdct = Mdct()
mp = MatchingPursuit(mdct,apf)
mp.buildMask(frame_size)

# pour chaque musique de la bdd on prend 3 extraits

extracts_k = [1./4,2./4,3./4]
counter = np.zeros(len(noises))
i = 0

for track in music_list:
        print(track)
        wavdata = sound.read(music_dir + "/" + track)
        lenght = wavdata.getnframes()
        fs = wavdata.getframerate()

        for coef in extracts_k:

                for k in range(len(database)):

                    for q in range(len(noises)):
                        wavdata.rewind()
                        wavdata.readframes(int(lenght*coef/(5*Fe*8192))*(5*Fe*8192))
                        db = database[k]
                        j=0
                        result = None
                        offsets = {}
                        while result == None and j < 30:
Пример #6
0
mp = MatchingPursuit(mdct, atoms_per_frame)
biggest_atom_size = mdct.sizes[-1]
Fe = 44100
frame_size = int(frame_duration*Fe/biggest_atom_size)*biggest_atom_size
mp.buildMask(frame_size)

for track in music_list:
    query = []
    track_title = track[:-4]

    database = Database()
    track_id = database.addTrack(track_title)
    del database
    print("=> Processing %s, id: %d" % (track_title, track_id))

    wavdata = sound.read(track)
    Fe = wavdata.getframerate()
    frame_number = int(wavdata.getnframes()/frame_size)

    print("%d frames to process for this track" % frame_number)
    
    progress = 0

    for i in range(frame_number):
        s = wavdata.readframes(frame_size)
        s = np.frombuffer(s, dtype='<i2') 
        y = mp.sparse(s)
        keys = mp.extractKeys(y)
        query.extend([(Binary(hash_key)[0:5],track_id, int(i*frame_size+offset)) for (hash_key,offset) in keys])

Пример #7
0
for file in os.listdir(music_dir):
	if file.endswith(".mp3"):
		music_list.append(file)

shaz = Shazam(100)

duration = 2

# pour chaque musique de la bdd on prend 3 extraits
extracts_k = [1./4, 2./4, 3./4]

counter = [0, 0, 0, 0, 0]

for track in music_list:
	print track
	wavdata = sound.read(music_dir + "/" + track)
	lenght = wavdata.getnframes()
	fs = wavdata.getframerate()

	for coef in extracts_k:
		wavdata.rewind()
		wavdata.readframes(int(lenght*coef))
		keys = shaz.processTrack(wavdata, int(duration*fs))

		found_keys = {}

		for index,db in enumerate(database):
			for key in keys:
				string = str(key[0]) + '-' + str(key[1]) + '-' + str(key[2])
				offset = int(key[3])
				key_hash = hashlib.sha1(string).digest()
Пример #8
0
mp = MatchingPursuit(mdct, atoms_per_frame)
biggest_atom_size = mdct.sizes[-1]
Fe = 44100
frame_size = int(frame_duration * Fe / biggest_atom_size) * biggest_atom_size
mp.buildMask(frame_size)

for track in music_list:
    query = []
    track_title = track[:-4]

    database = Database()
    track_id = database.addTrack(track_title)
    del database
    print("=> Processing %s, id: %d" % (track_title, track_id))

    wavdata = sound.read(track)
    Fe = wavdata.getframerate()
    frame_number = int(wavdata.getnframes() / frame_size)

    print("%d frames to process for this track" % frame_number)

    progress = 0

    for i in range(frame_number):
        s = wavdata.readframes(frame_size)
        s = np.frombuffer(s, dtype='<i2')
        y = mp.sparse(s)
        keys = mp.extractKeys(y)
        query.extend([(Binary(hash_key)[0:5], track_id,
                       int(i * frame_size + offset))
                      for (hash_key, offset) in keys])