voicesauce/opensauce-python

Rounding issue on Python 3

Closed this issue · 1 comments

Apparently, there is an issue with rounding in Python 3. This comes up in the implementation of shr_pitch():

# "time locations rounded to nearest ms"
#
# XXX numpy uses round-half-even, while matlab appears to use
# round-away-from-zero.  We can emulate this in python2 by using
# python2 round function instead of numpy's, but in python3 the
# rounding will have to take a detour through the Decimal module,
# which fortunately in python3 has a C accelerator.  Or perhaps
# we can ultimately just use round-half-even, if it turns out
# not to affect the results.  (This matters here because the time
# intervals produced by shrp are normally x.5 values.)
import sys
if sys.version_info.major > 2:
    raise NotImplementedError("python3 rounding will produce bad results")
t = np.vectorize(round)(f0_time)

Quoted from this commit: 7dcb050#diff-7953eb3de436b3d0e74a60971a8b027aR78

Currently, the code passes all tests except for anything involving shr_pitch() because of this rounding problem.

The solution is to write our own rounding function using NumPy functions. Since it uses NumPy, it works in both Python2 and Python3.

See this commit for the solution f2cfe4a