Skip to content

Commit d19f5b4

Browse files
update readme and test case
1 parent 9007810 commit d19f5b4

File tree

4 files changed

+42
-13
lines changed

4 files changed

+42
-13
lines changed

README.md

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,58 @@ streamlit run test/streamlit.py
4949

5050
### Python Examples
5151

52-
- *test/test.py*:
52+
Run the following test script after cloning this repo.
53+
54+
```shell script
55+
git clone https://github.com/haoheliu/voicefixer.git
56+
cd voicefixer
57+
python3 test/test.py # test script
58+
```
59+
We expect it will give you the following output:
60+
```shell script
61+
Initializing VoiceFixer...
62+
Test voicefixer mode 0, Pass
63+
Test voicefixer mode 1, Pass
64+
Test voicefixer mode 2, Pass
65+
Initializing 44.1kHz speech vocoder...
66+
Test vocoder using groundtruth mel spectrogram...
67+
Pass
68+
```
69+
*test/test.py* mainly contains the test of the following two APIs:
70+
- voicefixer.restore
71+
- vocoder.oracle
5372

5473
```python
5574
...
5675

5776
# TEST VOICEFIXER
5877
## Initialize a voicefixer
78+
print("Initializing VoiceFixer...")
5979
voicefixer = VoiceFixer()
60-
## Mode 0: Original Model (suggested by default)
61-
## Mode 1: Add preprocessing module (remove higher frequency)
62-
## Mode 2: Train mode (might work sometimes on seriously degraded real speech)
80+
# Mode 0: Original Model (suggested by default)
81+
# Mode 1: Add preprocessing module (remove higher frequency)
82+
# Mode 2: Train mode (might work sometimes on seriously degraded real speech)
6383
for mode in [0,1,2]:
84+
print("Testing mode",mode)
6485
voicefixer.restore(input=os.path.join(git_root,"test/utterance/original/original.flac"), # low quality .wav/.flac file
6586
output=os.path.join(git_root,"test/utterance/output/output_mode_"+str(mode)+".flac"), # save file path
6687
cuda=False, # GPU acceleration
6788
mode=mode)
89+
if(mode != 2):
90+
check("output_mode_"+str(mode)+".flac")
91+
print("Pass")
6892

6993
# TEST VOCODER
70-
## Initialize a vocoder. Only 44100 sampling rate is supported.
94+
## Initialize a vocoder
95+
print("Initializing 44.1kHz speech vocoder...")
7196
vocoder = Vocoder(sample_rate=44100)
7297

7398
### read wave (fpath) -> mel spectrogram -> vocoder -> wave -> save wave (out_path)
74-
vocoder.oracle(fpath=os.path.join(git_root,"test/utterance/original/original.flac"),
99+
print("Test vocoder using groundtruth mel spectrogram...")
100+
vocoder.oracle(fpath=os.path.join(git_root,"test/utterance/original/p360_001_mic1.flac"),
75101
out_path=os.path.join(git_root,"test/utterance/output/oracle.flac"),
76102
cuda=False) # GPU acceleration
77103

78-
# Other interfaces
79-
# voicefixer.restore_inmem
80-
# vocoder.forward
81104
...
82105
```
83106

test/test.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212

1313
import git
1414
import os
15+
import sys
1516
import librosa
1617
import numpy as np
17-
from voicefixer import VoiceFixer, Vocoder
1818

1919
git_root = git.Repo("", search_parent_directories=True).git.rev_parse("--show-toplevel")
20+
sys.path.append(git_root)
21+
from voicefixer import VoiceFixer, Vocoder
22+
2023
os.makedirs(os.path.join(git_root,"test/utterance/output"),exist_ok=True)
2124

2225
def check(fname):
@@ -31,31 +34,34 @@ def check(fname):
3134

3235
# TEST VOICEFIXER
3336
## Initialize a voicefixer
37+
print("Initializing VoiceFixer...")
3438
voicefixer = VoiceFixer()
3539
# Mode 0: Original Model (suggested by default)
3640
# Mode 1: Add preprocessing module (remove higher frequency)
3741
# Mode 2: Train mode (might work sometimes on seriously degraded real speech)
3842
for mode in [0,1,2]:
43+
print("Test voicefixer mode",mode,end=", ")
3944
voicefixer.restore(input=os.path.join(git_root,"test/utterance/original/original.flac"), # low quality .wav/.flac file
4045
output=os.path.join(git_root,"test/utterance/output/output_mode_"+str(mode)+".flac"), # save file path
4146
cuda=False, # GPU acceleration
4247
mode=mode)
4348
if(mode != 2):
4449
check("output_mode_"+str(mode)+".flac")
45-
50+
print("Pass")
4651

4752
# TEST VOCODER
4853
## Initialize a vocoder
54+
print("Initializing 44.1kHz speech vocoder...")
4955
vocoder = Vocoder(sample_rate=44100)
5056

5157
### read wave (fpath) -> mel spectrogram -> vocoder -> wave -> save wave (out_path)
52-
vocoder.oracle(fpath=os.path.join(git_root,"test/utterance/original/original.flac"),
58+
print("Test vocoder using groundtruth mel spectrogram...")
59+
vocoder.oracle(fpath=os.path.join(git_root,"test/utterance/original/p360_001_mic1.flac"),
5360
out_path=os.path.join(git_root,"test/utterance/output/oracle.flac"),
5461
cuda=False) # GPU acceleration
5562

5663
# Another interface
5764
# vocoder.forward(mel=mel)
58-
5965
check("oracle.flac")
6066

6167
print("Pass")
89.2 KB
Binary file not shown.

test/utterance/target/oracle.flac

-42.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)