This notebook shows how to interact with the ElevenLabs API to achieve text-to-speech capabilities.First, you need to set up an ElevenLabs account. You can follow the instructions here.
from langchain_community.tools import ElevenLabsText2SpeechTooltext_to_speak = "Hello world! I am the real slim shady"tts = ElevenLabsText2SpeechTool()tts.name
Copy
Ask AI
'eleven_labs_text2speech'
We can generate audio, save it to the temporary file and then play it.
audio_file = agent.run("Tell me a joke and read it out for me.")
Copy
Ask AI
> Entering new AgentExecutor chain...Action:\`\`\`{ "action": "eleven_labs_text2speech", "action_input": { "query": "Why did the chicken cross the playground? To get to the other slide!" }}\`\`\`Observation: /tmp/tmpsfg783f1.wavThought: I have the audio file ready to be sent to the humanAction:\`\`\`{ "action": "Final Answer", "action_input": "/tmp/tmpsfg783f1.wav"}\`\`\`> Finished chain.
Copy
Ask AI
tts.play(audio_file)
Assistant
Responses are generated using AI and may contain mistakes.