Set up json file
This commit is contained in:
parent
b2dd75319f
commit
3a4509f40a
@ -5,11 +5,12 @@ from scipy.io import wavfile
|
||||
import sounddevice as sd
|
||||
import random
|
||||
from pesq import pesq
|
||||
import json
|
||||
|
||||
|
||||
|
||||
SIGNAL_PATH = "speechfiles/sp01.wav"
|
||||
NOISE_PATH = "noisefiles/white.dat"
|
||||
#SIGNAL_PATH = "speechfiles/sp01.wav"
|
||||
#NOISE_PATH = "noisefiles/white.dat"
|
||||
|
||||
|
||||
# Scale the signal to the range [-1,1]
|
||||
@ -64,16 +65,53 @@ def add_noise(signal, noise, snr):
|
||||
|
||||
|
||||
def main():
|
||||
signal_sample_rate, signal_data = load_audiofile(SIGNAL_PATH)
|
||||
noise_sample_rate, noise_data = load_audiofile(NOISE_PATH)
|
||||
assert signal_sample_rate == noise_sample_rate, "Signal and noise sampling rates didn't match."
|
||||
sample_rate = signal_sample_rate
|
||||
noise_paths = ("noisefiles/white.dat", "noisefiles/train.dat", "noisefiles/street.dat", "noisefiles/exhibition.dat")
|
||||
|
||||
noisy_signal = add_noise(signal_data, noise_data, 0)
|
||||
filtered_signal = scipy.signal.wiener(noisy_signal)
|
||||
# Compose signal paths for the 30 sentences
|
||||
signal_paths = []
|
||||
for i in range(1,30+1):
|
||||
signal_paths.append(f"speechfiles/sp{i:02}.wav")
|
||||
|
||||
# SNR in dB
|
||||
snrs = (0, 10, 20, 30)
|
||||
|
||||
pesqs = {"unfiltered": {}, "filtered": {}}
|
||||
|
||||
for snr in snrs:
|
||||
pesqs["unfiltered"][snr] = {}
|
||||
pesqs["filtered"][snr] = {}
|
||||
|
||||
for noise_path in noise_paths:
|
||||
pesqs["filtered"][snr][noise_path[:-4]] = []
|
||||
pesqs["unfiltered"][snr][noise_path[:-4]] = []
|
||||
|
||||
for signal_path in signal_paths:
|
||||
noise_sample_rate, noise_data = load_audiofile(noise_path)
|
||||
signal_sample_rate, signal_data = load_audiofile(signal_path)
|
||||
|
||||
assert signal_sample_rate == noise_sample_rate, "Signal and noise sampling rates didn't match."
|
||||
sample_rate = signal_sample_rate
|
||||
|
||||
noisy_signal = add_noise(signal_data, noise_data, snr)
|
||||
filtered_signal = scipy.signal.wiener(noisy_signal)
|
||||
|
||||
noisy_pesq = pesq(sample_rate, signal_data, noisy_signal, mode='nb')
|
||||
filtered_pesq = pesq(sample_rate, signal_data, filtered_signal, mode='nb')
|
||||
|
||||
pesqs["filtered"][snr][noise_path[:-4]].append(noisy_pesq)
|
||||
pesqs["unfiltered"][snr][noise_path[:-4]].append(filtered_pesq)
|
||||
|
||||
pesqs_json = json.dumps(pesqs, indent=4)
|
||||
with open("pesqs.json", "w") as outfile:
|
||||
outfile.write(pesqs_json)
|
||||
|
||||
plt.plot(snrs, noisy_pesqs, label="PESQ Unfiltered")
|
||||
plt.plot(snrs, filtered_pesqs, label="PESQ Filtered")
|
||||
plt.xlabel("SNR [dB]")
|
||||
plt.ylabel("PESQ")
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
print(pesq(sample_rate, signal_data, noisy_signal, mode='nb'))
|
||||
print(pesq(sample_rate, signal_data, filtered_signal, mode='nb'))
|
||||
#sd.play(normalize_signal(noisy_signal), samplerate=sample_rate, blocking=True)
|
||||
#sd.play(normalize_signal(filtered_signal), samplerate=sample_rate, blocking=True)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user