Skip to content

Commit 3b950a5

Browse files
authored
Merge pull request JeremyCCHsu#3 from wuaalb/small-fixes
Small fixes
2 parents d28fb64 + e68b9e0 commit 3b950a5

File tree

4 files changed

+58
-70
lines changed

4 files changed

+58
-70
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ World/
44
src/
55
*.cpp
66
*.so
7+
*.pyd
8+
*.egg-info

README.md

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PyWorldVocoder<br/>A Python wrapper for World Vocoder
1+
# PyWorldVocoder - A Python wrapper for World Vocoder
22

33

44
| **`Linux`** |
@@ -9,17 +9,15 @@
99
Morise's World Vocoder is a fast and high-quality vocoder.
1010
World Vocoder parameterizes speech into three components:
1111

12-
5. Pitch (fundamental frequency, F0) contour
13-
2. smoothed spectrogram
14-
3. aperiodicity
12+
1. Pitch (fundamental frequency, F0) contour
13+
2. Harmonic spectral envelope
14+
3. Aperiodic spectral envelope (relative to the harmonic spectral envelope)
1515

1616
It can also resynthesize speech using these features (see examples below).
1717

1818
For more information, please visit [Morise's World repository](https://github.com/mmorise/World)
1919
and the [official website of World Vocoder](http://ml.cs.yamanashi.ac.jp/world/english/)
2020

21-
<br/>
22-
2321

2422
## I. APIs
2523

@@ -41,20 +39,20 @@ y = pw.synthesize(f0, sp, ap, fs, pyDioOpt.option['frame_period'])
4139
f0, sp, ap, pyDioOpt = pw.wav2world(x, fs)
4240
```
4341

44-
<br/>
4542

4643
## II. Installation
4744
### Environment/Dependencies
48-
- Linux Ubuntu 14.04/16.04
49-
- Python 2.7.6/3.5
50-
- Cython 0.24 (or later versions; required)
51-
- Scipy
52-
- Numpy
53-
- argparse
54-
- Matplotlib (optional; for demo.py only)
45+
- Linux Ubuntu 14.04/16.04, Windows
46+
- Python 2.7/3.5
47+
- Cython 0.24 (or later versions; required)
48+
- Numpy
49+
- argparse (optional; for demo.py only)
50+
- PySoundFile (optional; for demo.py only)
51+
- Matplotlib (optional; for demo.py only)
5552

5653
You can simply install these by `pip install -r requirements.txt`
5754

55+
5856
### Installation procedures
5957
```bash
6058
pip install -U pip
@@ -64,49 +62,48 @@ cd Python-Wrapper-for-World-Vocoder
6462
bash download_vocoder.sh
6563
python setup.py install
6664
```
67-
It will automatically `git clone` Morise's World Vocoder (C++ version).
68-
<br/>
65+
It will automatically `git clone` Morise's World Vocoder (C++ version).<br/>
66+
Alternatively you can clone or download the World repository manually and copy its "src" directory to this repositories directory.<br/>
6967
As for installation mode (the last line), you can choose from the following options.
7068

7169

7270
### Installation Mode
73-
9. If you want to "install" this package, try <br/>
74-
`python setup.py install`
75-
(add `--user` if you don't have root access)
76-
0. If you just want to try out some experiments, execute
77-
`python setup.py build_ext --inplace` <br/>
71+
1. If you want to "install" this package, try<br/>
72+
`python setup.py install`<br/>
73+
(add `--user` if you don't have root access)
74+
2. If you just want to try out some experiments, execute<br/>
75+
`python setup.py build_ext --inplace`<br/>
7876
Then you can use PyWorld from this directory.<br/>
79-
You can also copy the resulting **pyworld.so** file to
80-
`~/.local/lib/python2.7/site-packages` <br/>
81-
so that you can use it everywhere like an installed package.
77+
You can also copy the resulting **pyworld.so** (pyworld.{arch}.pyd on Windows) file to
78+
`~/.local/lib/python2.7/site-packages` (or corresponding Windows directory)
79+
so that you can use it everywhere like an installed package.<br/>
80+
Alternatively you can copy/symlink the compiled files using pip, e.g. `pip install -e .`
8281

8382

8483
### Validation
85-
You can validate installation by running
86-
`python demo.py`
84+
You can validate installation by running
85+
`python demo.py`
8786
to see if you get results in `test/` direcotry.
8887

89-
<br/>
9088

9189
## Troubleshooting
92-
0. Upgrade your Cython version to 0.24.<br/>
90+
1. Upgrade your Cython version to 0.24.<br/>
9391
(I failed to build it on Cython 0.20.1post0)<br/>
94-
It'll require you to download Cython form http://cython.org/ <br/>
92+
It'll require you to download Cython form http://cython.org/<br/>
9593
Unzip it, and `python setup.py install` it.<br/>
9694
(I tried `pip install Cython` but the upgrade didn't seem correct)<br/>
97-
(Again, add `--user` if you don't have root access.)
95+
(Again, add `--user` if you don't have root access.)
96+
2. The following code might be needed in some configurations:
9897

99-
1. The following code might be needed in some configurations:
100-
```python
101-
import matplotlib
102-
matplotlib.use('Agg')
103-
```
98+
```python
99+
import matplotlib
100+
matplotlib.use('Agg')
101+
```
104102

105-
<br/>
106103

107104
## Note:
108105
1. This wrapper is an updated version of sotelo's "world.py"<br/>
109-
https://github.com/sotelo/world.py
106+
https://github.com/sotelo/world.py
110107

111108
## TODO List
112109

demo.py

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,27 @@
1-
from __future__ import print_function
2-
import pyworld as pw
1+
from __future__ import division, print_function
2+
33
import os
44
from shutil import rmtree
5+
import argparse
6+
57
import numpy as np
6-
import matplotlib
7-
matplotlib.use('Agg')
8+
#import matplotlib
9+
#matplotlib.use('Agg')
810
import matplotlib.pyplot as plt
9-
from scipy.io.wavfile import read, write
10-
import argparse
11+
12+
import soundfile as sf
13+
import pyworld as pw
14+
1115

1216
parser = argparse.ArgumentParser()
1317
parser.add_argument("-r", "--frame_rate", type=int, default=5)
1418
parser.add_argument("-s", "--speed", type=int, default=1)
1519

16-
# =================================
17-
SHORT_MAX = 32767
18-
EPSILON = 1e-8
19-
def wavread(filename):
20-
fs, x = read(filename)
21-
x = x.astype(np.float) / SHORT_MAX
22-
return x, fs
23-
24-
25-
def wavwrite(filename, fs, y):
26-
ymax = np.max(np.abs(y))
27-
if ymax < 1.0:
28-
y = y * SHORT_MAX
29-
else:
30-
y = (y / ymax) * SHORT_MAX
31-
y = y.astype(np.int16)
32-
write(filename, fs, y)
3320

21+
EPSILON = 1e-8
3422

3523
def savefig(filename, figlist, log=True):
36-
h = 10
24+
#h = 10
3725
n = len(figlist)
3826
# peek into instances
3927
f = figlist[0]
@@ -46,26 +34,27 @@ def savefig(filename, figlist, log=True):
4634
plt.xlim([0, len(f)])
4735
elif len(f.shape) == 2:
4836
Nsmp, dim = figlist[0].shape
49-
figsize=(h * float(Nsmp) / dim, len(figlist) * h)
50-
plt.figure(figsize=figsize)
37+
#figsize=(h * float(Nsmp) / dim, len(figlist) * h)
38+
#plt.figure(figsize=figsize)
39+
plt.figure()
5140
for i, f in enumerate(figlist):
5241
plt.subplot(n, 1, i+1)
5342
if log:
54-
plt.imshow(np.log(f.T + EPSILON))
43+
x = np.log(f + EPSILON)
5544
else:
56-
plt.imshow(f.T + EPSILON)
45+
x = f + EPSILON
46+
plt.imshow(x.T, origin='lower', interpolation='none', aspect='auto', extent=(0, x.shape[0], 0, x.shape[1]))
5747
else:
5848
raise ValueError('Input dimension must < 3.')
5949
plt.savefig(filename)
60-
# =================================
6150

6251

6352
def main(args):
6453
if os.path.isdir('test'):
6554
rmtree('test')
6655
os.mkdir('test')
6756

68-
x, fs = wavread('utterance/vaiueo2d.wav')
57+
x, fs = sf.read('utterance/vaiueo2d.wav')
6958

7059
# 1. A convient way
7160
f0, sp, ap, pyDioOpt = pw.wav2world(x, fs) # use default options
@@ -84,14 +73,14 @@ def main(args):
8473
_sp = pw.cheaptrick(x, _f0, t, fs)
8574
_ap = pw.d4c(x, _f0, t, fs)
8675
_y = pw.synthesize(_f0, _sp, _ap, fs, pyDioOpt.option['frame_period'])
87-
wavwrite('test/y_without_f0_refinement.wav', fs, _y)
76+
sf.write('test/y_without_f0_refinement.wav', _y, fs)
8877

8978
# 2-2 With F0 refinement (using stonemask)
9079
f0 = pw.stonemask(x, _f0, t, fs)
9180
sp = pw.cheaptrick(x, f0, t, fs)
9281
ap = pw.d4c(x, f0, t, fs)
9382
y = pw.synthesize(f0, sp, ap, fs, pyDioOpt.option['frame_period'])
94-
wavwrite('test/y_with_f0_refinement.wav', fs, y)
83+
sf.write('test/y_with_f0_refinement.wav', y, fs)
9584

9685
# Comparison
9786
savefig('test/wavform.png', [x, _y, y])

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
numpy
22
matplotlib
3-
scipy
43
argparse
54
cython
5+
pysoundfile

0 commit comments

Comments
 (0)