Beispiel #1
0
 def show_test_vad_record(self, time):
     wav = self.record_test_audio(time)
     if not wav is None:
         test(wav, self.nbc)
         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)
Beispiel #2
0
    def fft_analyzer_record(self, time):
        if time.get() == 0:
            time.set(self.default_audio_time)

        wav = self.record_test_audio(time)
        if not wav is None:
            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)
Beispiel #3
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")
Beispiel #4
0
def test():
    wav = WavFile(path_to_test + '12345678910.wav')
    freq, amplitude = FFT.fft(wav)
    freq1, amplitude1 = FFT.fft_db_amplitude_wav(wav)

    plotter = Plotter("Test FFT Single")
    plotter.add_sub_plot_data("data", wav.samples)
    plotter.add_sub_plot_data("fft_log_fft", amplitude, freq, scale_x='log', scale_y='log')
    plotter.add_sub_plot_data("fft_log_fft_db_hz", amplitude1, freq1, scale_x='log', scale_y='log')

    plotter.sub_plot_all_horizontal()
Beispiel #5
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)
Beispiel #6
0
def test_all_audio():
    sin = WavFile(path_to_test + 'sin100Hz.wav')
    noise = WavFile(path_to_test + 'noise.wav')
    m = WavFile(path_to_test + 'meandr25Hz.wav')
    freq_sin, amplitude_sin = FFT.fft_db_amplitude_wav(sin)
    freq_noise, amplitude_noise = FFT.fft_db_amplitude_wav(noise)
    freq_m, amplitude_m = FFT.fft_db_amplitude_wav(m)

    plotter = Plotter("Test FFT Multiple")
    plotter.add_sub_plot_data("sin 100 Hz", sin.samples)
    plotter.add_sub_plot_data("fft sin 100 Hz", amplitude_sin, freq_sin, scale_x='log', scale_y='log')
    plotter.add_sub_plot_data("noise", noise.samples)
    plotter.add_sub_plot_data("fft noise", amplitude_noise, freq_noise, scale_y='log')
    plotter.add_sub_plot_data("meandr25Hz", m.samples)
    plotter.add_sub_plot_data("fft meandr 25 Hz", amplitude_m[0:2500], freq_m[0:2500], scale_y='log')

    plotter.sub_plot_all_horizontal()
Beispiel #7
0
def plot_result(wav, word_results, params, min_params, colors, items):
    file = Plotter("DAF")
    file.add_sub_plot_data("Digitized audio file", wav.get_one_channel_data(), x_label="Samples", y_label="Amplitude")
    for i in word_results.keys():
        file.add_line_at("Digitized audio file", list(map(lambda x: x * items, word_results[i]["starts"])), "x",
                         colors[i], lw=3)
        file.add_line_at("Digitized audio file", list(map(lambda x: x * items, word_results[i]["ends"])), "x",
                         colors[i], lw=3)
        file.sub_plot_all_horizontal(show=False, save=True)

    energy = Plotter("Energy")
    energy.add_sub_plot_data("Energy", params["energy"], x_label="Frames", y_label="Energy Value")
    energy.add_line_at("Energy", min_params["energy"], "y", color="red")
    energy.sub_plot_all_horizontal(show=False, save=True)

    mdf = Plotter("MDF")
    mdf.add_sub_plot_data("Most Dominant Frequency", params["mdf"], x_label="Frames", y_label="MDF Value")
    mdf.add_line_at("Most Dominant Frequency", min_params["mdf"], "y", color="red")
    mdf.sub_plot_all_horizontal(show=False, save=True)

    zcr = Plotter("ZCR")
    zcr.add_sub_plot_data("Zero Crossing Rate", params["zcr"], x_label="Frames", y_label="ZCR Value")
    zcr.add_line_at("Zero Crossing Rate", min_params["zcr"], "y", color="red")
    zcr.sub_plot_all_horizontal(show=False, save=True)

    zcr = Plotter("SFM")
    zcr.add_sub_plot_data("Spectral Flatness Measure", params["sfm"], x_label="Frames", y_label="SFM Value")
    zcr.add_line_at("Spectral Flatness Measure", min_params["sfm"], "y", color="red")
    zcr.sub_plot_all_horizontal(show=False, save=True)
Beispiel #8
0
def test():
    file = WavFile(path_to_test + "12345678910.wav")
    freq, amplitude = FFT.fft_db_amplitude_wav(file)
    out = FiniteImpulseFilter.filter(amplitude, 100, file.frame_rate, 20, 50, "hemming")

    file_plotter = Plotter("FIR Test DAF")
    file_plotter.add_sub_plot_data("Digitized audio file", file.samples, x_label="Samples", y_label="Amplitude")
    file_plotter.sub_plot_all_horizontal()

    fft_plotter = Plotter("FIR Test FFT")
    fft_plotter.add_sub_plot_data("Fast Fourier Transform", amplitude, freq, scale_x='log', scale_y='log',
                                  x_label="Frequency (Hz)", y_label="Amplitude (db)")
    fft_plotter.sub_plot_all_horizontal()

    fft_plotter = Plotter("FIR Test FIR_FFT")
    fft_plotter.add_sub_plot_data("Fast Fourier Transform After FIR", out, freq, scale_x='log', scale_y='log',
                                  x_label="Frequency (Hz)", y_label="Amplitude (db)")
    fft_plotter.sub_plot_all_horizontal()