Source code for langchain.tools.edenai.audio_text_to_speech
from __future__ import annotations
import logging
from typing import Dict, List, Literal, Optional
import requests
from langchain.callbacks.manager import CallbackManagerForToolRun
from langchain.pydantic_v1 import Field, root_validator, validator
from langchain.tools.edenai.edenai_base_tool import EdenaiTool
logger = logging.getLogger(__name__)
[docs]class EdenAiTextToSpeechTool(EdenaiTool):
    """Tool that queries the Eden AI Text to speech API.
    for api reference check edenai documentation:
    https://docs.edenai.co/reference/audio_text_to_speech_create.
    To use, you should have
    the environment variable ``EDENAI_API_KEY`` set with your API token.
    You can find your token here: https://app.edenai.run/admin/account/settings
    """
    name = "edenai_text_to_speech"
    description = (
        "A wrapper around edenai Services text to speech."
        "Useful for when you need to convert text to speech."
        """the output is a string representing the URL of the audio file,
        or the path to the downloaded wav file """
    )
    language: Optional[str] = "en"
    """
    language of the text passed to the model.
    """
    # optional params see api documentation for more info
    return_type: Literal["url", "wav"] = "url"
    rate: Optional[int]
    pitch: Optional[int]
    volume: Optional[int]
    audio_format: Optional[str]
    sampling_rate: Optional[int]
    voice_models: Dict[str, str] = Field(default_factory=dict)
    voice: Literal["MALE", "FEMALE"]