Custom TTS for eleven labs implementation

Hey all, new to the forum here. I am looking at implementing a custom TTS engine. Yes, I know there is a long list of supported engines, but I am attempting to use eleven labs specifically. I am at a point where (I think) I implemented all the architecture necessary, but for some reason the TTS simply is not working. I verified that the problem essentially rests either in the tts file itself, or on the mycroft side of things. Here is my mycroft conf file:

{ "max_allowed_core_version": 21.2, "tts": { "elevenlabs": { "voice_id": "voice id here", "api_key": "my api key here" }, "module": "elevenlabs" } }

and my elevenlabs_tts.py:
`
import requests
from .tts import TTS, TTSValidator
from mycroft.configuration import Configuration

_API_URL = “https://api.elevenlabs.io/v1/text-to-speech

class ElevenLabsTTS(TTS):
def init(self, lang, config):
super(ElevenLabsTTS, self).init(lang, config, ElevenLabsTTSValidator(self))
self.config = Configuration.get().get(“tts”, {}).get(“elevenlabs”, {})
self.voice_id = self.config.get(“voice_id”)
self.api_key = self.config.get(“api_key”)
self.type = “mp3”

def get_tts(self, sentence, mp3_file):
    url = "{}/{}".format(_API_URL, self.voice_id)
    headers = {
        "Accept": "audio/mpeg",
        "Content-Type": "application/json",
        "xi-api-key": self.api_key
    }
    data = {
        "text": sentence,
        "voice_settings": {
            "stability": 0,
            "similarity_boost": 0
        }
    }
    response = requests.post(url, json=data, headers=headers)

    CHUNK_SIZE = 1024
    with open(mp3_file, 'wb') as f:
        for chunk in response.iter_content(chunk_size=CHUNK_SIZE):
            if chunk:
                f.write(chunk)

    return (mp3_file, None)  # No phonemes

class ElevenLabsTTSValidator(TTSValidator):
def init(self, tts):
super(ElevenLabsTTSValidator, self).init(tts)

def validate_lang(self):
    # Assuming Eleven Labs API supports the language set in Mycroft
    return True

def validate_connection(self):
    # Assuming the API key and voice ID are correct
    return True

def get_tts_class(self):
    return ElevenLabsTTS`

I have verified that the api works in a separate Python example, so there isn’t something wrong with the api key or voice id. Also, I included the file my importing in tts.py:

from mycroft.tts.elevenlabs_tts import ElevenLabsTTS
and
"elevenlabs": ElevenLabsTTS ← under CLASSES

For some reason, still, I cannot get mycroft to use the custom module. It seems like this should work considering the same implementation for other files, but something is clearly missing.

you probably want to migrate to OVOS plugin manager

https://openvoiceos.github.io/ovos-technical-manual/tts_plugins

1 Like

try using this new python api: https://github.com/elevenlabs/elevenlabs-python.git