|
9 | 9 | from fileHandler import FileHandler |
10 | 10 |
|
11 | 11 | # sin |
12 | | - |
13 | 12 | def test1(): |
14 | 13 |
|
15 | 14 | frequency = 3; |
@@ -612,10 +611,95 @@ def test6(): |
612 | 611 | axs[2].plot(np.linspace(0, samples, samples), cep) |
613 | 612 | plt.show() |
614 | 613 |
|
| 614 | +def test7(src, frame_time, start_time): |
| 615 | + y, samplingrate = librosa.load(src) |
| 616 | + start_sample = int(start_time * samplingrate) |
| 617 | + samples = int(frame_time * samplingrate) |
| 618 | + end_sample = start_sample + samples |
| 619 | + f_time = np.linspace(0, 1000*frame_time, samples) |
| 620 | + |
| 621 | + fig, axs = plt.subplots(20) |
| 622 | + fig_all, axs_all = plt.subplots(1) |
| 623 | + |
| 624 | + max_value = np.zeros(20) |
| 625 | + sum_value = np.zeros(20) |
| 626 | + center = np.zeros(20) |
| 627 | + |
| 628 | + for i in range(0, 20): |
| 629 | + print(f"Round: {i}") |
| 630 | + |
| 631 | + axs[i].plot(f_time, y[start_sample:end_sample]) |
| 632 | + |
| 633 | + lpc_values = librosa.lpc(y[start_sample:end_sample], order=12) |
| 634 | + axs2[i].plot(np.linspace(0, 13, 13), lpc_values, label="test") |
| 635 | + axs2[i].plot(np.linspace(0, 13, 13), lpc_to_lpcc(lpc_values), label="lpcc") |
| 636 | + axs_all.plot(np.linspace(0, 13, 13), lpc_values, label=f"Round: {i}") |
| 637 | + |
| 638 | + if max_value[i] < np.abs(np.max(lpc_values)): |
| 639 | + max_value[i] = np.abs(np.max(lpc_values)) |
| 640 | + |
| 641 | + for j in range(0, 13): |
| 642 | + sum_value[i] += np.abs(lpc_values[j]) |
| 643 | + center[i] += j * np.abs(lpc_values[j]) |
| 644 | + center[i] = center[i] / sum_value[i] |
| 645 | + |
| 646 | + start_sample += samples |
| 647 | + end_sample+= samples |
| 648 | + |
| 649 | + fig_overall, axs_overall = plt.subplots(1) |
| 650 | + axs_overall.plot(np.linspace(0, 20, 20), max_value, label="max") |
| 651 | + axs_center.plot(np.linspace(0, 20, 20), center, label=f"center {frame_time}") |
| 652 | + axs_center.legend() |
| 653 | + axs_overall.legend() |
| 654 | + |
| 655 | + plt.ylim(-1000, 1000) |
| 656 | + |
| 657 | +def plotAudio(src): |
| 658 | + y, samplingrate = librosa.load(src) |
| 659 | + |
| 660 | + plt.plot(np.linspace(0, y.shape[0]/samplingrate, y.shape[0]), y) |
| 661 | + plt.show() |
| 662 | + |
| 663 | +def lpc_to_lpcc(lpc): |
| 664 | + lpcc = np.zeros(lpc.shape) |
| 665 | + lpcc[0] = lpc[0] |
| 666 | + for i in range(2, lpc.shape[0] + 1): |
| 667 | + lpcc[i-1] = sum((1-k/i)* lpc[k-1] * lpcc[i-k-1] for k in range(1, i)) + lpc[i-1] |
| 668 | + return lpcc |
615 | 669 | # test2() |
616 | 670 | # test3() |
617 | 671 | # burg_marple(4, [1.0,2.0,3.0, 4.0]) |
618 | | -test6() |
| 672 | + |
| 673 | +# plotAudio("C:\\Users\\SCU8BH\\Documents\\T3000\\Hallo, das ist ein Test.wav") |
| 674 | +# plotAudio("C:\\Users\\SCU8BH\\Documents\\T3000\\Account einloggen.wav") |
| 675 | + |
| 676 | +fig_x, axs_center = plt.subplots(1) |
| 677 | +fig2, axs2 = plt.subplots(20) |
| 678 | +test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Hallo, das ist ein Test.wav", 0.1, 1.44) |
| 679 | +test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Hallo, das ist ein Test.wav", 0.05, 1.44) |
| 680 | +test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Hallo, das ist ein Test.wav", 0.01, 1.44) |
| 681 | +fig_x, axs_center = plt.subplots(1) |
| 682 | +fig2, axs2 = plt.subplots(20) |
| 683 | +test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Account einloggen.wav", 0.1, 0.89) |
| 684 | +test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Account einloggen.wav", 0.05, 0.89) |
| 685 | +test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Account einloggen.wav", 0.01, 0.89) |
| 686 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0000\\Speaker_0000_00000.wav") |
| 687 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0000\\Speaker_0000_00001.wav") |
| 688 | +# fig2, axs2 = plt.subplots(20) |
| 689 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0001\\Speaker_0001_00000.wav") |
| 690 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0001\\Speaker_0001_00001.wav") |
| 691 | +# fig2, axs2 = plt.subplots(20) |
| 692 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0002\\Speaker_0002_00000.wav") |
| 693 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0002\\Speaker_0002_00001.wav") |
| 694 | +# fig2, axs2 = plt.subplots(20) |
| 695 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0003\\Speaker_0003_00000.wav") |
| 696 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0003\\Speaker_0003_00001.wav") |
| 697 | +# fig2, axs2 = plt.subplots(20) |
| 698 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0004\\Speaker_0004_00000.wav") |
| 699 | +# test7("C:\\Users\\SCU8BH\\Documents\\T3000\\Studienarbeit\\Data\\50_speakers_audio_data\\Speaker_0004\\Speaker_0004_00001.wav") |
| 700 | +plt.legend() |
| 701 | +plt.show() |
| 702 | + |
619 | 703 |
|
620 | 704 | # print(librosa.lpc(np.array([13.77, 13.6, 13.11, 12.38, 11.48, 10.45]), order=1)) |
621 | 705 | # print(librosa.lpc(np.array([13.77, 13.6, 13.11, 12.38, 11.48, 10.45]), order=2)) |
|
0 commit comments