bootphon / phonemizer

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

GitHub Issue Title: Permission Denied Error when Running on Cloud Issue Description: #165

Closed 106AbdulBasit closed 3 weeks ago

106AbdulBasit commented 5 months ago

*Issue Description: I'm encountering a "Home directory not accessible: Permission denied" error when attempting to run the following code on a cloud environment. The code is using the Phonemizer library for phonemizing text. It runs successfully on a local machine, but the issue arises when trying to execute it in a cloud environment

from phonemizer.backend import EspeakBackend
from phonemizer.punctuation import Punctuation
from phonemizer.separator import Separator

# remove all the punctuation from the text, considering only the specified
# punctuation marks
text = Punctuation(';:,.!"?()-').remove(text)

# build the set of all the words in the text
words = {w.lower() for line in text for w in line.strip().split(' ') if w}

# initialize the espeak backend for English
backend = EspeakBackend('en-us')

# separate phones by a space and ignoring words boundaries
separator = Separator(phone=' ', word=None)

# build the lexicon by phonemizing each word one by one. The backend.phonemize
# function expects a list as input and outputs a list.
lexicon = {
    word: backend.phonemize([word], separator=separator, strip=True)[0]
    for word in words}

Error Message:

Home directory not accessible: Permission denied Home directory not accessible: Permission denied

Context: The script executes successfully on a local machine, but the error occurs when attempting to run it in a cloud environment. The issue seems to be related to home directory permissions

Steps to Reproduce:

Execute the provided code on a local machine. Attempt to run the same code on a cloud environment. Additional Information:

The code is using the Phonemizer library. The error suggests a permission issue related to home directory access. The script is expected to remove punctuation and phonemize words. Environment:

Local Machine: ubntu[wsl] Cloud Environment: vast.ai Python Version: 3.8 Phonemizer Library Version: 3.2.1

mmmaat commented 5 months ago

Hi, your issue is not related to phonemizer but to your environment. I suppose the exception is raised by the line backend = EspeakBackend('en-us') because under the scene the espeak library is copied into a temp directory (https://github.com/bootphon/phonemizer/blob/master/phonemizer/backend/espeak/api.py#L66).

If this is confirmed you can try fixing a call to tempfile.mkdtemp() in your cloud. What is strange is that usually tempdir is going to /tmp by default, not to /home...