Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support model file, training bug fixes and sanity checks #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ While it is meant to be used as a library, a simple command-line tool is
provided as an example. It operates on RAW 16-bit (machine endian) mono
PCM files sampled at 48 kHz. It can be used as:

./examples/rnnoise_demo <number of channels> <maximum attenuation> < input.raw > output.raw
./examples/rnnoise_demo < input.raw > < output.raw > [< model file >]

The output is also a 16-bit raw PCM file.
4 changes: 3 additions & 1 deletion TRAINING
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# NOTE: Required pip packages - 'numpy', 'keras'. Recommended pip packages - 'tensorflow'

(1) cd src ; ./compile.sh

(2) ./denoise_training signal.raw noise.raw count > training.f32
Expand All @@ -8,4 +10,4 @@

(4) ./rnn_train.py

(5) ./dump_rnn.py weights.hdf5 ../src/rnn_data.c ../src/rnn_data.h
(5) ./dump_rnn.py weights.hdf5 ../src/rnn_data.c trained_model.txt orig
33 changes: 30 additions & 3 deletions examples/rnnoise_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,36 @@ int main(int argc, char **argv) {
int i;
int first = 1;
float x[FRAME_SIZE];
RNNModel *model = NULL;
FILE *f1, *fout;
FILE *model_fptr;
DenoiseState *st;
st = rnnoise_create(NULL);
if (argc!=3) {
fprintf(stderr, "usage: %s <noisy speech> <output denoised>\n", argv[0]);

if (argc < 3) {
fprintf(stderr, "usage: %s <noisy speech> <output denoised> [<model file>]\n", argv[0]);
return 1;
}
if (argc >= 4) {
model_fptr = fopen(argv[3], "r");
if (!model_fptr) {
fprintf(stderr, "Error opening model file \n");
return 1;
}
model = rnnoise_model_from_file(model_fptr);
if (!model) {
fprintf(stderr, "Model not found \n");
return 1;
}
}

st = rnnoise_create(model);
f1 = fopen(argv[1], "r");
fout = fopen(argv[2], "w");
if (!f1) {
fprintf(stderr, "Error opening input audio file\n");
return 1;
}

while (1) {
short tmp[FRAME_SIZE];
fread(tmp, sizeof(short), FRAME_SIZE, f1);
Expand All @@ -54,7 +75,13 @@ int main(int argc, char **argv) {
first = 0;
}
rnnoise_destroy(st);
if (model) {
rnnoise_model_free(model);
}
fclose(f1);
fclose(fout);
if (model_fptr) {
fclose(model_fptr);
}
return 0;
}
10 changes: 9 additions & 1 deletion src/denoise.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void compute_band_corr(float *bandE, const kiss_fft_cpx *X, const kiss_fft_cpx *

void interp_band_gain(float *g, const float *bandE) {
int i;
memset(g, 0, FREQ_SIZE);
memset(g, 0, FREQ_SIZE * sizeof(float));
for (i=0;i<NB_BANDS-1;i++)
{
int j;
Expand Down Expand Up @@ -534,7 +534,15 @@ int main(int argc, char **argv) {
return 1;
}
f1 = fopen(argv[1], "r");
if (!f1) {
fprintf(stderr, "Error opening speech samples file %s\n", argv[1]);
return 1;
}
f2 = fopen(argv[2], "r");
if (!f2) {
fprintf(stderr, "Error opening noise samples file %s\n", argv[2]);
return 1;
}
maxCount = atoi(argv[3]);
for(i=0;i<150;i++) {
short tmp[FRAME_SIZE];
Expand Down
3 changes: 2 additions & 1 deletion training/dump_rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def printLayer(f, ft, layer):
weights = layer.get_weights()
activation = re.search('function (.*) at', str(layer.activation)).group(1).upper()
if len(weights) > 2:
ft.write('{} {} '.format(weights[0].shape[0], weights[0].shape[1]/3))
ft.write('{} {} '.format(weights[0].shape[0], int(weights[0].shape[1]/3)))
else:
ft.write('{} {} '.format(weights[0].shape[0], weights[0].shape[1]))
if activation == 'SIGMOID':
Expand Down Expand Up @@ -105,3 +105,4 @@ def mean_squared_sqrt_error(y_true, y_pred):
#hf.write('};\n')

f.close()
ft.close()