Back to Llama Index

We use one of the Azure resources of an insurance call for the next example.

llama-index-integrations/tools/llama-index-tools-azure-speech/examples/azure_speech.ipynb

0.14.211.3 KB
Original Source
python
import os
os.environ["OPENAI_API_KEY"] = "sk-proj-1234567890"
python
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
python
from llama_index.tools.azure_speech.base import AzureSpeechToolSpec
from llama_index.tools.azure_translate.base import AzureTranslateToolSpec
from llama_index.core.workflow import Context

speech_tool = AzureSpeechToolSpec(speech_key="your-key", region="eastus")
translate_tool = AzureTranslateToolSpec(api_key="your-key", region="eastus")

agent = FunctionAgent(
    tools=[*speech_tool.to_tool_list(), *translate_tool.to_tool_list()],
    llm=OpenAI(model="gpt-4.1"),
)
ctx = Context(agent)

print(await agent.run('Say "hello world"', ctx=ctx))
python
# We use one of the Azure resources of an insurance call for the next example.
# Use this cell to download the file, or put your own file in data/speech.wav
import urllib.request

urllib.request.urlretrieve(
    "https://speechstudiorawgithubscenarioscdn.azureedge.net/call-center/sampledata/Call1_separated_16k_health_insurance.wav",
    "data/speech.wav",
)
python
print(await agent.run("transcribe and format conversation in data/speech.wav", ctx=ctx))
python
print(await agent.run("translate the conversation into spanish", ctx=ctx))