bootphon / phonemizer

Simple text to phones converter for multiple languages
https://bootphon.github.io/phonemizer/
GNU General Public License v3.0
1.2k stars 166 forks source link

Windows issue with NamedTemporaryFile #21

Closed snowzhangy closed 5 years ago

snowzhangy commented 5 years ago

when i run phonemize on windows 10 , python 3.6 i still have issue. it looks the temp file doesn't created at all. (the backslash issue fixed i can see)

>>> ph=phonemize('Hello World',strip=False,njobs=1,backend='espeak')
Failed to read file 'C:\Users\cinetec\AppData\Local\Temp\tmp5sigu2vf'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\cinetec\AppData\Local\Programs\Python\Python36\lib\site-packages\phonemizer-1.0.1-py3.6.egg\phonemizer\phonemize.py", line 94, in phonemize
    text, separator=separator, strip=strip, njobs=njobs)
  File "C:\Users\cinetec\AppData\Local\Programs\Python\Python36\lib\site-packages\phonemizer-1.0.1-py3.6.egg\phonemizer\backend.py", line 130, in phonemize
    out = self._phonemize_aux(self._list2str(text), separator, strip)
  File "C:\Users\cinetec\AppData\Local\Programs\Python\Python36\lib\site-packages\phonemizer-1.0.1-py3.6.egg\phonemizer\backend.py", line 235, in _phonemize_aux
    shlex.split(command, posix=False)).decode('utf8')
  File "C:\Users\cinetec\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "C:\Users\cinetec\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['espeak', '-ven-us', '--ipa=3', '-q', '-f', 'C:\\Users\\cinetec\\AppData\\Local\\Temp\\tmp5sigu2vf']' returned non-zero exit status 1.
mmmaat commented 5 years ago

I do not have a windows machine to test it... But few stuff you can do:

CorentinJ commented 5 years ago

I'm having the same issue. The command will fail if there are spaces in any of the paths to begin with, but even without I meet the same error as @snowzhangy:

subprocess.CalledProcessError: Command 
'['D:\\Users\\Corentin\\Documents\\Utilities\\CLI\\espeak.exe', '-ven-us', '--ipa=3',
 '-q', '-f', 'C:\\Users\\Valiox\\AppData\\Local\\Temp\\tmp76tt0mot']' 
returned non-zero exit status 1.

(breaks added for readability)

Running that identical command in CLI but on another text file works without issues.

CorentinJ commented 5 years ago

I guess something is wrong with NamedTemporaryFile on windows, because using a regular file works fine.

mmmaat commented 5 years ago

Indeed from Python doc they say: Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later).

I'm working on a fix.

mmmaat commented 5 years ago

I pushed a commit in the branch issue21.

As I said I do not have Windows so I cannot check myself. Could you please test if the bug is fixed on that branch and let me know?

Thanks.

mmmaat commented 5 years ago

The idea is to use tmpfile.close() instead of tmpfile.seek(0)

CorentinJ commented 5 years ago

Yep, that fixes it 👍

mmmaat commented 5 years ago

Thanks, merged into master