vocode-python icon indicating copy to clipboard operation
vocode-python copied to clipboard

Unable to import any synthesizer if GTTS is not installed.

Open zaptrem opened this issue 2 years ago • 3 comments

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)

zaptrem avatar Jun 01 '23 18:06 zaptrem

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.

github-actions[bot] avatar Apr 05 '24 01:04 github-actions[bot]

This issue has been automatically closed due to inactivity. Thank you for your contributions.

github-actions[bot] avatar Apr 12 '24 01:04 github-actions[bot]

This is important, I will review it.

arpagon avatar Apr 12 '24 15:04 arpagon

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.

github-actions[bot] avatar Jun 12 '24 01:06 github-actions[bot]

This issue has been automatically closed due to inactivity. Thank you for your contributions.

github-actions[bot] avatar Jun 19 '24 01:06 github-actions[bot]

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

coyotwill avatar Nov 01 '24 17:11 coyotwill