diff --git a/libs/community/langchain_community/tools/eleven_labs/text2speech.py b/libs/community/langchain_community/tools/eleven_labs/text2speech.py index 91fd89b37..83997857d 100644 --- a/libs/community/langchain_community/tools/eleven_labs/text2speech.py +++ b/libs/community/langchain_community/tools/eleven_labs/text2speech.py @@ -7,6 +7,8 @@ from langchain_core.utils import get_from_dict_or_env from pydantic import model_validator +from types import GeneratorType + def _import_elevenlabs() -> Any: try: @@ -68,7 +70,11 @@ def _run( with tempfile.NamedTemporaryFile( mode="bx", suffix=".mp3", delete=False ) as f: - f.write(speech) + if isinstance(speech, GeneratorType): + for byte_chunk in speech: + f.write(byte_chunk) + else: + f.write(speech) return f.name except Exception as e: raise RuntimeError(f"Error while running ElevenLabsText2SpeechTool: {e}")