이 노트북은 ElevenLabs API와 상호작용하여 text-to-speech 기능을 구현하는 방법을 보여줍니다. 먼저 ElevenLabs 계정을 설정해야 합니다. 여기의 지침을 따라 진행할 수 있습니다.
pip install -qU  elevenlabs langchain-community
import os

os.environ["ELEVENLABS_API_KEY"] = ""

Usage

from langchain_community.tools import ElevenLabsText2SpeechTool

text_to_speak = "Hello world! I am the real slim shady"

tts = ElevenLabsText2SpeechTool()
tts.name
'eleven_labs_text2speech'
오디오를 생성하고 임시 파일에 저장한 다음 재생할 수 있습니다.
speech_file = tts.run(text_to_speak)
tts.play(speech_file)
또는 오디오를 직접 스트리밍할 수 있습니다.
tts.stream_speech(text_to_speak)

Agent 내에서 사용하기

from langchain.agents import AgentType, initialize_agent, load_tools
from langchain_openai import OpenAI
llm = OpenAI(temperature=0)
tools = load_tools(["eleven_labs_text2speech"])
agent = initialize_agent(
    tools=tools,
    llm=llm,
    agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
)
audio_file = agent.run("Tell me a joke and read it out for me.")
> 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.wav
Thought: I have the audio file ready to be sent to the human
Action:
\`\`\`
{
  "action": "Final Answer",
  "action_input": "/tmp/tmpsfg783f1.wav"
}
\`\`\`



> Finished chain.
tts.play(audio_file)

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I