vocode-python
vocode-python copied to clipboard
Unable to import any synthesizer if GTTS is not installed.
When doing the following:
from vocode.turn_based.synthesizer import AnyNonGoogleSynthesizer
The following error occurs when the optional dependency GTTS isn't installed since it's imported by the init file:
Traceback (most recent call last):
File "main.py", line 19, in <module>
from coqui_synthesizer import CoquiSynthesizer
File "/home/runner/YC-Telegram-Bot/coqui_synthesizer.py", line 7, in <module>
from vocode.turn_based.synthesizer.base_synthesizer import BaseSynthesizer
File "/home/runner/YC-Telegram-Bot/venv/lib/python3.10/site-packages/vocode/turn_based/synthesizer/__init__.py", line 7, in <module>
from vocode.turn_based.synthesizer.google_synthesizer import GoogleSynthesizer
File "/home/runner/YC-Telegram-Bot/venv/lib/python3.10/site-packages/vocode/turn_based/synthesizer/google_synthesizer.py", line 6, in <module>
from google.cloud import texttospeech_v1beta1 as tts
ImportError: cannot import name 'texttospeech_v1beta1' from 'google.cloud' (unknown location)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed due to inactivity. Thank you for your contributions.
This is important, I will review it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This issue has been automatically closed due to inactivity. Thank you for your contributions.
Here is my workaround for this issue. Add this to a file that is loaded early in your application:
import logging
import sys
from types import ModuleType
google_cloud_patched = False
# Avoid dependency on google.cloud when it's not installed
try:
import google.cloud
except ModuleNotFoundError:
# Patch vocode to avoid depending on google.cloud
class DummyGoogleSynthModule(ModuleType):
GoogleSynthesizer = None
sys.modules['vocode.turn_based.synthesizer.google_synthesizer'] = DummyGoogleSynthModule(f'Module disabled in {__file__}')
logging.info("Google Cloud module not installed. Patched.")
google_cloud_patched = True