The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
PR comments
mateusz.wosinski1b7caa1a29e5
diff --git a/libs/langchain/langchain/tools/eleven_labs/models.py b/libs/langchain/langchain/tools/eleven_labs/models.pynew file mode 100644index 0000000000..c977b2972f--- /dev/null+++ b/libs/langchain/langchain/tools/eleven_labs/models.py@@ -0,0 +1,8 @@+from enum import Enum+++class ElevenLabsModel(str, Enum):+ """Models available for Eleven Labs Text2Speech."""++ MULTI_LINGUAL = "eleven_multilingual_v1"+ MONO_LINGUAL = "eleven_monolingual_v1"diff --git a/libs/langchain/langchain/tools/eleven_labs/text2speech.py b/libs/langchain/langchain/tools/eleven_labs/text2speech.pyindex e59652fb19..5c6edb00b9 100644--- a/libs/langchain/langchain/tools/eleven_labs/text2speech.py+++ b/libs/langchain/langchain/tools/eleven_labs/text2speech.py@@ -1,10 +1,19 @@import tempfile-from typing import Dict+from typing import Dict, Unionfrom langchain.pydantic_v1 import root_validatorfrom langchain.tools.base import BaseTool+from langchain.tools.eleven_labs.models import ElevenLabsModelfrom langchain.utils import get_from_dict_or_env+try:+ import elevenlabs++except ImportError:+ raise ImportError(+ "elevenlabs is not installed. " "Run `pip install elevenlabs` to install."+ )+class ElevenLabsText2SpeechTool(BaseTool):"""Tool that queries the Eleven Labs Text2Speech API.@@ -13,6 +22,8 @@ class ElevenLabsText2SpeechTool(BaseTool):https://docs.elevenlabs.io/welcome/introduction"""+ model: Union[ElevenLabsModel, str] = ElevenLabsModel.MULTI_LINGUAL+name: str = "eleven_labs_text2speech"description: str = ("A wrapper around Eleven Labs Text2Speech. "@@ -29,16 +40,7 @@ class ElevenLabsText2SpeechTool(BaseTool):return valuesdef _text2speech(self, text: str) -> str:- try:- from elevenlabs import generate-- except ImportError:- raise ImportError(- "elevenlabs is not installed. "- "Run `pip install elevenlabs` to install."- )-- speech = generate(text=text, model="eleven_multilingual_v1")+ speech = elevenlabs.generate(text=text, model=self.model)with tempfile.NamedTemporaryFile(mode="bx", suffix=".wav", delete=False) as f:f.write(speech)return f.name@@ -53,32 +55,13 @@ class ElevenLabsText2SpeechTool(BaseTool):def play(self, speech_file: str) -> None:"""Play the text as speech."""- try:- from elevenlabs import play-- except ImportError:- raise ImportError(- "elevenlabs is not installed. "- "Run `pip install elevenlabs` to install."- )with open(speech_file, mode="rb") as f:speech = f.read()- play(speech)+ elevenlabs.play(speech)def stream(self, query: str) -> None:- """Stream the text as speech."""-- try:- from elevenlabs import generate, stream-- except ImportError:- raise ImportError(- "elevenlabs is not installed. "- "Run `pip install elevenlabs` to install."- )-- speech_stream = generate(- text=query, model="eleven_multilingual_v1", stream=True- )- stream(speech_stream)+ """Stream the text as speech as it is generated.+ Play the text in your speakers."""+ speech_stream = elevenlabs.generate(text=query, model=self.model, stream=True)+ elevenlabs.stream(speech_stream)