예제 #1
0
    def test_pitch_raw_using_creaper(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or REAPER version issues.
        # Data was generated on Manjaro Linux.

        for fn in wav_fns:
            # Estimate F0 using REAPER, use default VoiceSauce values
            t_raw, F0_raw = creaper_pitch(fn, reaper_path=default_reaper_path,
                                          frame_shift=1, max_pitch=500,
                                          min_pitch=40, high_pass=True,
                                          hilbert_transform=False, inter_mark=10)

            # Get sample time data
            time_sample = get_sample_data(fn, 'reaper', 'rtF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(t_raw), len(time_sample))
            # Check that computed time and sample_data are "close enough" for
            # floating precision
            self.assertAllClose(t_raw, time_sample, rtol=1e-05, atol=1e-08)

            # Get sample F0 data
            F0_sample = get_sample_data(fn, 'reaper', 'reaperF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(F0_raw), len(F0_sample))
            # Check that computed F0 and sample_data are "close enough" for
            # floating precision
            self.assertAllClose(F0_raw, F0_sample, rtol=1e-05, atol=1e-08, equal_nan=True)
예제 #2
0
    def test_pitch_raw(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or Praat version issues.
        # Data was generated by Praat v6.0.29 on Manjaro Linux.

        for fn in wav_fns:
            # Estimate raw Praat F0
            t_raw, F0_raw = praat_raw_pitch(fn, default_praat_path,
                                            frame_shift=1, method='cc',
                                            min_pitch=40, max_pitch=500,
                                            silence_threshold=0.03,
                                            voice_threshold=0.45,
                                            octave_cost=0.01,
                                            octave_jumpcost=0.35,
                                            voiced_unvoiced_cost=0.14,
                                            kill_octave_jumps=False,
                                            interpolate=False, smooth=False,
                                            smooth_bandwidth=5)
            # Get sample time data
            sample_data = get_sample_data(fn, 'praat', 'ptF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(t_raw), len(sample_data))
            # Check that computed time and sample_data are "close enough" for
            # floating precision
            self.assertAllClose(t_raw, sample_data, rtol=1e-05, atol=1e-08)

            # Get sample F0 data
            sample_data = get_sample_data(fn, 'praat', 'pF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(F0_raw), len(sample_data))
            # Check that computed F0 and sample_data are "close enough" for
            # floating precision
            self.assertTrue((np.isclose(F0_raw, sample_data, rtol=1e-05, atol=1e-08) | (np.isnan(F0_raw) & np.isnan(sample_data))).all())
예제 #3
0
    def test_pitch_raw_using_creaper(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or REAPER version issues.
        # Data was generated on Manjaro Linux.

        for fn in wav_fns:
            # Estimate F0 using REAPER, use default VoiceSauce values
            t_raw, F0_raw = creaper_pitch(fn,
                                          reaper_path=default_reaper_path,
                                          frame_shift=1,
                                          max_pitch=500,
                                          min_pitch=40,
                                          high_pass=True,
                                          hilbert_transform=False,
                                          inter_mark=10)

            # Get sample time data
            time_sample = get_sample_data(fn, 'reaper', 'rtF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(t_raw), len(time_sample))
            # Check that computed time and sample_data are "close enough" for
            # floating precision
            self.assertAllClose(t_raw, time_sample, rtol=1e-05, atol=1e-08)

            # Get sample F0 data
            F0_sample = get_sample_data(fn, 'reaper', 'reaperF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(F0_raw), len(F0_sample))
            # Check that computed F0 and sample_data are "close enough" for
            # floating precision
            self.assertAllClose(F0_raw,
                                F0_sample,
                                rtol=1e-05,
                                atol=1e-08,
                                equal_nan=True)
예제 #4
0
    def test_pitch_raw(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or snack version issues.
        # Data was generated by snack 2.2.10 on Manjaro Linux.
        for fn in wav_fns:
            F0_raw, V_raw = snack_raw_pitch(fn,
                                            snack_method,
                                            frame_shift=1,
                                            window_size=25,
                                            max_pitch=500,
                                            min_pitch=40,
                                            tcl_shell_cmd=tcl_cmd)

            # Check V data
            # Voice is 0 or 1, so (hopefully) no FP rounding issues.
            sample_data = get_sample_data(fn, 'snack', 'sV', '1ms')
            # Check that all voice data is either 0 or 1
            self.assertTrue(np.all((V_raw == 1) | (V_raw == 0)))
            self.assertTrue(np.all((sample_data == 1) | (sample_data == 0)))
            # Check number of entries is consistent
            self.assertEqual(len(V_raw), len(sample_data))
            # Check actual data values are "close enough",
            # within floating precision
            self.assertAllClose(V_raw, sample_data, rtol=1e-05, atol=1e-08)

            # Check F0 data
            sample_data = get_sample_data(fn, 'snack', 'sF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(F0_raw), len(sample_data))
            # Check that F0 and sample_data are "close enough" for
            # floating precision
            if not np.allclose(F0_raw, sample_data, rtol=1e-05, atol=1e-08):
                # If first check fails, try lowering relative tolerance and
                # redoing the check
                idx = np.where(np.isclose(F0_raw, sample_data) == False)[0]
                print('\nChecking F0 data using rtol=1e-05, atol=1e-08 in {}:'.
                      format(fn))
                print(
                    'Out of {} array entries in F0 snack data, discrepancies in these indices'
                    .format(len(F0_raw)))
                for i in idx:
                    print('idx {}, OpenSauce F0 = {}, sample F0 = {}'.format(
                        i, F0_raw[i], sample_data[i]))
                print(
                    'Reducing relative tolerance to rtol=3e-05 and redoing check:'
                )
                self.assertAllClose(F0_raw,
                                    sample_data,
                                    rtol=3e-05,
                                    atol=1e-08)
                print('OK')
            else:
                self.assertAllClose(F0_raw,
                                    sample_data,
                                    rtol=1e-05,
                                    atol=1e-08)
예제 #5
0
    def test_pitch_using_pyreaper(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or REAPER version issues.
        # Data was generated on Manjaro Linux.
        for fn in wav_fns:
            # Frame shift
            f_len = 1

            # Need ns (number of samples) and sampling rate (Fs) from wav file
            # to compute data length
            sound_file = SoundFile(fn)
            data_len = np.int_(np.floor(sound_file.ns / sound_file.fs / f_len * 1000))

            # Estimate F0 using REAPER, use default VoiceSauce values
            F0_os = reaper_pitch(sound_file, data_len, use_pyreaper=True,
                                 frame_shift=f_len, max_pitch=500,
                                 min_pitch=40, high_pass=True,
                                 hilbert_transform=False, inter_mark=10)
            # Get sample F0 data
            F0_sample_from_data = get_sample_data(fn, 'reaper', 'reaperF0', '1ms')
            # Fill full length F0 vector
            F0_sample = np.full(data_len, np.nan)
            F0_sample[:len(F0_sample_from_data)] = F0_sample_from_data
            # Check that F0 values are "close"
            self.assertAllClose(F0_os, F0_sample, rtol=1e-05, atol=1e-08, equal_nan=True)
예제 #6
0
    def test_formants_raw(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or Praat version issues.
        # Data was generated by Praat v6.0.29 on Manjaro Linux.

        for fn in wav_fns:
            # Get raw Praat formant estimates
            estimates_raw = praat_raw_formants(fn,
                                               default_praat_path,
                                               frame_shift=1,
                                               window_size=25,
                                               num_formants=4,
                                               max_formant_freq=6000)

            for n in self.formants4_names:
                # Get sample data corresponding to key name
                sample_data = get_sample_data(fn, 'praat', n, '1ms')
                # Check number of entries is consistent
                self.assertEqual(len(estimates_raw[n]), len(sample_data))
                # Check that our estimates and sample_data are "close enough"
                # for floating precision
                self.assertTrue((np.isclose(
                    estimates_raw[n], sample_data, rtol=1e-05, atol=1e-08) |
                                 (np.isnan(estimates_raw[n])
                                  & np.isnan(sample_data))).all())
예제 #7
0
    def test_formants_raw(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or snack version issues.
        # Data was generated by snack 2.2.10 on Manjaro Linux.
        for fn in wav_fns:
            estimates_raw = snack_raw_formants(fn,
                                               snack_method,
                                               frame_shift=1,
                                               window_size=25,
                                               pre_emphasis=0.96,
                                               lpc_order=12,
                                               tcl_shell_cmd=tcl_cmd)

            # Get sample data
            sample_data = {}
            for n in sformant_names:
                sample_data[n] = get_sample_data(fn, 'snack', n, '1ms')

            # Check number of entries is consistent
            for n in sformant_names:
                self.assertEqual(len(estimates_raw[n]), len(sample_data[n]))
            # Check that estimates and sample_data are "close enough" for
            # floating precision
            for n in sformant_names:
                # Increase rtol from 1e-5 to 1e-3 to account for random seed
                # used in Snack formants
                self.assertAllClose(estimates_raw[n],
                                    sample_data[n],
                                    rtol=1e-03,
                                    atol=1e-08)
예제 #8
0
    def test_pitch_raw(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or Praat version issues.
        # Data was generated by Praat v6.0.29 on Manjaro Linux.

        for fn in wav_fns:
            # Estimate raw Praat F0
            t_raw, F0_raw = praat_raw_pitch(fn,
                                            default_praat_path,
                                            frame_shift=1,
                                            method='cc',
                                            min_pitch=40,
                                            max_pitch=500,
                                            silence_threshold=0.03,
                                            voice_threshold=0.45,
                                            octave_cost=0.01,
                                            octave_jumpcost=0.35,
                                            voiced_unvoiced_cost=0.14,
                                            kill_octave_jumps=False,
                                            interpolate=False,
                                            smooth=False,
                                            smooth_bandwidth=5)
            # Get sample time data
            sample_data = get_sample_data(fn, 'praat', 'ptF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(t_raw), len(sample_data))
            # Check that computed time and sample_data are "close enough" for
            # floating precision
            self.assertAllClose(t_raw, sample_data, rtol=1e-05, atol=1e-08)

            # Get sample F0 data
            sample_data = get_sample_data(fn, 'praat', 'pF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(F0_raw), len(sample_data))
            # Check that computed F0 and sample_data are "close enough" for
            # floating precision
            self.assertTrue(
                (np.isclose(F0_raw, sample_data, rtol=1e-05, atol=1e-08) |
                 (np.isnan(F0_raw) & np.isnan(sample_data))).all())
예제 #9
0
    def test_pitch_raw(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or snack version issues.
        # Data was generated by snack 2.2.10 on Manjaro Linux.
        for fn in wav_fns:
            F0_raw, V_raw = snack_raw_pitch(fn, snack_method, frame_shift=1, window_size=25, max_pitch=500, min_pitch=40, tcl_shell_cmd=tcl_cmd)

            # Check V data
            # Voice is 0 or 1, so (hopefully) no FP rounding issues.
            sample_data = get_sample_data(fn, 'snack', 'sV', '1ms')
            # Check that all voice data is either 0 or 1
            self.assertTrue(np.all((V_raw == 1) | (V_raw == 0)))
            self.assertTrue(np.all((sample_data == 1) | (sample_data == 0)))
            # Check number of entries is consistent
            self.assertEqual(len(V_raw), len(sample_data))
            # Check actual data values are "close enough",
            # within floating precision
            self.assertAllClose(V_raw, sample_data, rtol=1e-05, atol=1e-08)

            # Check F0 data
            sample_data = get_sample_data(fn, 'snack', 'sF0', '1ms')
            # Check number of entries is consistent
            self.assertEqual(len(F0_raw), len(sample_data))
            # Check that F0 and sample_data are "close enough" for
            # floating precision
            if not np.allclose(F0_raw, sample_data, rtol=1e-05, atol=1e-08):
                # If first check fails, try lowering relative tolerance and
                # redoing the check
                idx = np.where(np.isclose(F0_raw, sample_data) == False)[0]
                print('\nChecking F0 data using rtol=1e-05, atol=1e-08 in {}:'.format(fn))
                print('Out of {} array entries in F0 snack data, discrepancies in these indices'.format(len(F0_raw)))
                for i in idx:
                    print('idx {}, OpenSauce F0 = {}, sample F0 = {}'.format(i, F0_raw[i], sample_data[i]))
                print('Reducing relative tolerance to rtol=3e-05 and redoing check:')
                self.assertAllClose(F0_raw, sample_data, rtol=3e-05, atol=1e-08)
                print('OK')
            else:
                self.assertAllClose(F0_raw, sample_data, rtol=1e-05, atol=1e-08)
예제 #10
0
    def test_formants_raw(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or Praat version issues.
        # Data was generated by Praat v6.0.29 on Manjaro Linux.

        for fn in wav_fns:
            # Get raw Praat formant estimates
            estimates_raw = praat_raw_formants(fn, default_praat_path,
                                               frame_shift=1, window_size=25,
                                               num_formants=4,
                                               max_formant_freq=6000)

            for n in self.formants4_names:
                # Get sample data corresponding to key name
                sample_data = get_sample_data(fn, 'praat', n, '1ms')
                # Check number of entries is consistent
                self.assertEqual(len(estimates_raw[n]), len(sample_data))
                # Check that our estimates and sample_data are "close enough"
                # for floating precision
                self.assertTrue((np.isclose(estimates_raw[n], sample_data, rtol=1e-05, atol=1e-08) | (np.isnan(estimates_raw[n]) & np.isnan(sample_data))).all())
예제 #11
0
    def test_formants_raw(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or snack version issues.
        # Data was generated by snack 2.2.10 on Manjaro Linux.
        for fn in wav_fns:
            estimates_raw = snack_raw_formants(fn, snack_method, frame_shift=1, window_size=25, pre_emphasis=0.96, lpc_order=12, tcl_shell_cmd=tcl_cmd)

            # Get sample data
            sample_data = {}
            for n in sformant_names:
                sample_data[n] = get_sample_data(fn, 'snack', n, '1ms')

            # Check number of entries is consistent
            for n in sformant_names:
                self.assertEqual(len(estimates_raw[n]), len(sample_data[n]))
            # Check that estimates and sample_data are "close enough" for
            # floating precision
            for n in sformant_names:
                # Increase rtol from 1e-5 to 1e-3 to account for random seed
                # used in Snack formants
                self.assertAllClose(estimates_raw[n], sample_data[n], rtol=1e-03, atol=1e-08)
예제 #12
0
    def test_pitch_using_creaper(self):
        # Test against previously generated data to make sure nothing has
        # broken and that there are no cross platform or REAPER version issues.
        # Data was generated on Manjaro Linux.
        for fn in wav_fns:
            # Frame shift
            f_len = 1

            # Need ns (number of samples) and sampling rate (Fs) from wav file
            # to compute data length
            sound_file = SoundFile(fn)
            data_len = np.int_(
                np.floor(sound_file.ns / sound_file.fs / f_len * 1000))

            # Estimate F0 using REAPER, use default VoiceSauce values
            F0_os = reaper_pitch(sound_file,
                                 data_len,
                                 use_pyreaper=False,
                                 reaper_path=default_reaper_path,
                                 frame_shift=f_len,
                                 max_pitch=500,
                                 min_pitch=40,
                                 high_pass=True,
                                 hilbert_transform=False,
                                 inter_mark=10)
            # Get sample F0 data
            F0_sample_from_data = get_sample_data(fn, 'reaper', 'reaperF0',
                                                  '1ms')
            # Fill full length F0 vector
            F0_sample = np.full(data_len, np.nan)
            F0_sample[:len(F0_sample_from_data)] = F0_sample_from_data
            # Check that F0 values are "close"
            self.assertAllClose(F0_os,
                                F0_sample,
                                rtol=1e-05,
                                atol=1e-08,
                                equal_nan=True)