コード例 #1
0
ファイル: Library.py プロジェクト: KOlexandr/Audio
    def find_max_corrcoef_and_word(self, test_samples, max_length):
        """
        1. corrects length of all items in library
        2. counts FFT of all items
        3. find coefficient of correlation between items in library and test samples
        4. returns word with max coefficient of correlation

        @param test_samples: test audio file
        @param max_length: maximum length of part of test file
        @return: found word and coefficient of correlation
        """
        new_max_length = max(self.max_length, max_length)
        if new_max_length != self.max_length:
            self.need_count_fft = True
            self.need_correct_length = True
            self.max_length = new_max_length

        self.correct_length_of_all_items()
        self.count_fft_for_all_items()
        word, coefficient = None, 0
        test_fft = self.fft(correct_len(test_samples, self.max_length))
        for i in self.items:
            tmp_coefficient = np.corrcoef(abs(i.fft), abs(test_fft))
            if tmp_coefficient[0][1] > coefficient:
                word = i.word
                coefficient = tmp_coefficient[0][1]
        return word, coefficient
コード例 #2
0
ファイル: __init__.py プロジェクト: KOlexandr/Audio
 def fft_diff_len(x):
     """
     Fast Fourier transform for different lists which can have length not power of 2
     function correct length and if all ok run fft
     @param x: list of data
     @return: list with fft
     """
     if is_power_of_2(len(x)):
         return FFT.fft(x)
     else:
         return FFT.fft_diff_len(correct_len(x, is_pow_of_2=True))