Example #1
0
 def fft_analyzer_select(self, path=path_to_test):
     askopenfile = filedialog.askopenfile(filetypes=[("Wave audio files", "*.wav *.wave")], defaultextension=".wav",
                                          initialdir=path)
     if not askopenfile is None:
         wav = WavFile(askopenfile.name)
         result_str = FFTVoiceAnalyzer.analyze(wav, self.processor)
         messagebox.showinfo("Result", result_str)
         if show_plots:
             plot = Plotter("DRA")
             plot.add_sub_plot_data("Digitized Recorded Audio", wav.get_one_channel_data(), x_label="Samples",
                                    y_label="Amplitude")
             plot.sub_plot_all_horizontal(show=False, save=True)
     else:
         messagebox.showwarning("Warning", "You should select one file. Please, try again")
Example #2
0
def create_files(wav, word_results, items, nbc):
    data = wav.get_one_channel_data()
    for i in word_results.keys():
        starts = word_results[i]['starts']
        ends = word_results[i]['ends']
        num = 1
        for k in range(0, len(starts)):
            file_name = 'word' + str(num) + "_" + str(i) + '.wav'
            file_items = data[starts[k] * items:ends[k] * items]
            if not nbc is None and use_nbc_for_vad:
                if len(file_items) > 10000 and nbc.get_class(nbc.get_classes(nbc.classify(
                        WavFile(samples=WavFile.to_binary(file_items), sample_width=wav.sample_width,
                                time=1)))) == "speech":
                    WavFile.write(path_to_vad_results + file_name, file_items, 0)
                    num += 1
            else:
                if len(file_items) > 10000:
                    WavFile.write(path_to_vad_results + file_name, file_items, 0)
                    num += 1
Example #3
0
 def create_lib_with_examples(self):
     """
     creates new library and adds all files from base folder as items
     @return: new Library object
     """
     example_waves = WavFile.get_all_waves(get_files(self.base_lib_folder, self.extension))
     lib = Library(self.fft, really_transform=self.really_transform)
     for i in example_waves:
         lib.create_and_add_item_from_wave(i)
     return lib
Example #4
0
    def create_sin_test(time, sample_rate, file_name=None, amplitude=32767, freq_hz=100, is_plot=False):
        """
        create test audio file with sin
        @param time: length of audio (seconds)
        @param sample_rate: sample rate (44100 Hz for example)
        @param file_name: name of file for save or None, if you don't wont to save file
        @param amplitude: max amplitude
        @param freq_hz: dominant frequency
        @param is_plot: flag for plot file data
        """
        buf_size = sample_rate*time

        buffer = list(numpy.zeros(buf_size, int))
        for i in range(buf_size):
            buffer[i] += int(amplitude * math.sin(float(2 * math.pi * i * freq_hz / sample_rate)))

        if is_plot:
            plotter = Plotter("Created Sin Test")
            plotter.add_sub_plot_data("data", buffer)
            plotter.sub_plot_all_horizontal()

        if not file_name is None:
            WavFile.write(file_name, buffer, time)