pythonaudioscipywavaudacity

Why extract sample from wav file using udacity gui and scipy give different values?


I have an audio wav file of 7seconds: full.wav.

I extract a small sample of it. I select the timeframe using audacity and I label it. I export the label (containing start and end time of the sample).

1/ I export the sample using audacity menu and save it as sample_audacity.wav

2/ I load in a python script the full.wav using scipy.io.wavfile.read I save the sample full[start:end]. It gives me sample_python.wav

When I listen to sample_audacity.wav and sample_python.wav I hear the same.

But if I load both of them using scipy.io.wavfile.read I got very different values for the 2 files. the values of sample_python.wav are subset of the values of full.wav - which is normal.

But the values of sample_audacity.wav are not.

Does someone know why/how audacity is modifying the initial data (full.wav) when saving an extract of it?

And if possible how to get audacity to give me as sample that will have same values (subset) of the initial data?

As an example, the first 100 values of sample_audacity.wav

[128 122 124 123 134 138 143 142 139 135 144 149 155 156 148 144 143 144 151 152 159 152 160 150 157 151 155 153 155 156 154 151 145 139 128 132 124 131 130 129 123 115 104 100 94 94 88 85 78 74 65 59 52 48 43 45 46 45 40 30 19 10 6 7 14 15 12 0 -8 1 23 51 72 63 55 26 23 20 31 36 40 35 27 22 15 15 7 9 1 -2 -4 0 -3 -4 -18 -25 -25 -12 -1 -9]

Shape of sample_audacity.wav: (36296,)

the first 100 values of sample_python.wav

[128 127 124 122 125 132 139 143 142 138 137 142 150 155 155 149 144 142 145 150 154 156 156 155 155 154 153 153 154 155 156 154 151 145 138 131 128 127 129 131 129 123 114 105 99 95 93 89 84 79 73 66 59 52 47 44 45 46 45 39 31 19 10 5 8 13 16 11 0 -7 0 23 52 69 68 50 30 20 22 30 37 39 35 28 21 16 13 10 7 2 -3 -3 -1 -1 -6 -17 -26 -24 -12 -2]

Shape of sample_python.wav: (36297,)

Audacity 2.1.2 Ubuntu

Preferences import/export: enter image description here

Export settings: enter image description here

Media info for both files: enter image description here


Solution

  • Once the file is imported into audacity, it is converted to 32-bit format. When you re-export the file back to 16-bits, audacity will dither the audio according to the preferences. There are more details on this page: https://wiki.audacityteam.org/wiki/Dither

    This export setting is not in an obvious location. Go to Preferences/Quality and then Dither under the "High Quality Conversion" heading. If you set this to None you should get the same results as python.