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

Whitespace in model path #54

Closed
etfre opened this issue Apr 28, 2021 · 4 comments · Fixed by #64
Closed

Whitespace in model path #54

etfre opened this issue Apr 28, 2021 · 4 comments · Fixed by #64

Comments

@etfre
Copy link

etfre commented Apr 28, 2021

I'm running into the following error when I try to use a model that contains a whitespace in its path:

[StardewSpeak] Speech engine error: ERR:     self._compiler = KaldiCompiler(self._options['model_dir'], tmp_dir=self._options['tmp_dir'],
[StardewSpeak] Speech engine error: ERR:   File "C:\Program Files (x86)\GOG Galaxy\Games\Stardew Valley\Mods\StardewSpeak\StardewSpeak\lib\speech-client\lib\site-packages\dragonfly\engines\backend_kaldi\compiler.py", line 70, in __init__
[StardewSpeak] Speech engine error: ERR:     KaldiAGCompiler.__init__(self, model_dir=model_dir, tmp_dir=tmp_dir, **kwargs)
[StardewSpeak] Speech engine error: ERR:   File "C:\Program Files (x86)\GOG Galaxy\Games\Stardew Valley\Mods\StardewSpeak\StardewSpeak\lib\speech-client\lib\site-packages\kaldi_active_grammar\compiler.py", line 201, in __init__
[StardewSpeak] Speech engine error: ERR:     self.model = Model(model_dir, tmp_dir)
[StardewSpeak] Speech engine error: ERR:   File "C:\Program Files (x86)\GOG Galaxy\Games\Stardew Valley\Mods\StardewSpeak\StardewSpeak\lib\speech-client\lib\site-packages\kaldi_active_grammar\model.py", line 221, in __init__
[StardewSpeak] Speech engine error: ERR:     self.phone_to_int_dict = { phone: i for phone, i in load_symbol_table(self.files_dict['phones.txt']) }
[StardewSpeak] Speech engine error: ERR:   File "C:\Program Files (x86)\GOG Galaxy\Games\Stardew Valley\Mods\StardewSpeak\StardewSpeak\lib\speech-client\lib\site-packages\kaldi_active_grammar\utils.py", line 187, in load_symbol_table
[StardewSpeak] Speech engine error: ERR:     with open(filename, 'r', encoding='utf-8') as f:
[StardewSpeak] Speech engine error: ERR: OSError: [Errno 22] Invalid argument: '"C:\\Users\\evfre\\.stardew speak\\models\\kaldi_model\\phones.txt"'

However, when I comment out the line self.files_dict.update({ k: '"%s"' % v for (k, v) in self.files_dict.items() if v and ' ' in v }) in the Model constructor, everything works as expected.

@daanzu
Copy link
Owner

daanzu commented Apr 29, 2021

Good find! However, I think this may now be moot in the latest versions, which don't need to use the command line utilities. Can you give it a try?

Relatedly, I am working on improving freezing. I haven't tried cx_freeze, but I have had success with using winpython.

@etfre
Copy link
Author

etfre commented Aug 3, 2021

Sorry for the late response. I can reproduce this in 2.1.0 as well, even without freezing:

File "C:\Program Files (x86)\GOG Galaxy\Games\Stardew Valley\Mods\StardewSpeak\StardewSpeak\lib\speech-client\lib\site-packages\kaldi_active_grammar\utils.py", line 194, in load_symbol_table
    with open(filename, 'r', encoding='utf-8') as f:
OSError: [Errno 22] Invalid argument: '"C:\\Program Files (x86)\\GOG Galaxy\\Games\\Stardew Valley\\Mods\\StardewSpeak\\StardewSpeak\\lib\\speech-client\\models\\kaldi_model\\phones.txt"'

Removing the above line in the Model __init__ method still fixes the issue for me.

@daanzu
Copy link
Owner

daanzu commented Aug 4, 2021

@evfredericksen Hmm, strange. Thanks for the report and retest! I will try to figure out what is causing it.

@etfre
Copy link
Author

etfre commented Aug 4, 2021

No problem. I don't have context for why the line was added originally, but I would think that the quotation marks around the path are unnecessary as Python should be able to handle whitespace in paths without any extra logic.

https://stackoverflow.com/questions/14852140/whitespaces-in-the-path-of-windows-filepath

Sample script:

import os
path_with_whitespace = os.path.join(os.getcwd(), "text.txt")
print(path_with_whitespace)
with open(path_with_whitespace) as f:
    pass
with open(f'"{path_with_whitespace}"') as f:
    pass

Result:

C:\Users\evfre\wp\test path\text.txt
Traceback (most recent call last):
  File "r.py", line 6, in <module>
    with open(f'"{path_with_whitespace}"') as f:
OSError: [Errno 22] Invalid argument: '"C:\\Users\\evfre\\wp\\test path\\text.txt"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants