# Custom TTS for eleven labs implementation

**URL:** https://community.openconversational.ai/t/custom-tts-for-eleven-labs-implementation/13598
**Category:** This category is being retired - Support
**Created:** [May 1, 2023, 3:09am UTC](https://community.openconversational.ai/t/custom-tts-for-eleven-labs-implementation/13598 "2023-05-01T03:09:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jeebus](https://community.openconversational.ai/letter_avatar_proxy/v4/letter/j/258eb7/32.png) [@Jeebus](https://community.openconversational.ai/u/Jeebus)
#### Post date: [May 1, 2023, 3:09am UTC](https://community.openconversational.ai/t/custom-tts-for-eleven-labs-implementation/13598/1 "2023-05-01T03:09:22Z")

</div>

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](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.

---

<div class="post-metadata">

### Author: ![JarbasAl](https://community.openconversational.ai/user_avatar/community.openconversational.ai/jarbasal/32/1319_2.png) [@JarbasAl](https://community.openconversational.ai/u/JarbasAl)
#### Post date: [May 1, 2023, 3:54am UTC](https://community.openconversational.ai/t/custom-tts-for-eleven-labs-implementation/13598/2 "2023-05-01T03:54:23Z")

</div>

you probably want to migrate to OVOS plugin manager

[https://openvoiceos.github.io/ovos-technical-manual/tts\_plugins](https://openvoiceos.github.io/ovos-technical-manual/tts_plugins)

---

<div class="post-metadata">

### Author: ![g3ar-v](https://community.openconversational.ai/user_avatar/community.openconversational.ai/g3ar-v/32/3862_2.png) [@g3ar-v](https://community.openconversational.ai/u/g3ar-v)
#### Post date: [May 8, 2023, 9:06pm UTC](https://community.openconversational.ai/t/custom-tts-for-eleven-labs-implementation/13598/3 "2023-05-08T21:06:36Z")

</div>

> [@Jeebus](#):
>
> 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”

try using this new python api: [https://github.com/elevenlabs/elevenlabs-python.git](https://github.com/elevenlabs/elevenlabs-python.git)
