-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from raldone01/feat/support_custom_endpoints
Support custom openai compatible endpoints
- Loading branch information
Showing
10 changed files
with
85 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
{ | ||
"domain": "openai_tts", | ||
"name": "OpenAI TTS", | ||
"codeowners": ["@sfortis"], | ||
"codeowners": [ | ||
"@sfortis" | ||
], | ||
"config_flow": true, | ||
"dependencies": [], | ||
"documentation": "https://github.com/sfortis/openai_tts/", | ||
"iot_class": "cloud_polling", | ||
"issue_tracker": "https://github.com/sfortis/openai_tts/issues", | ||
"requirements": ["requests>=2.25.1"], | ||
"version": "0.2.1" | ||
"requirements": [ | ||
"requests>=2.25.1" | ||
], | ||
"version": "0.2.2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
import requests | ||
|
||
from .const import URL | ||
|
||
|
||
class OpenAITTSEngine: | ||
|
||
def __init__(self, api_key: str, voice: str, model: str, speed: int): | ||
def __init__(self, api_key: str, voice: str, model: str, speed: int, url: str): | ||
self._api_key = api_key | ||
self._voice = voice | ||
self._model = model | ||
self._speed = speed | ||
self._url = URL | ||
self._url = url | ||
|
||
def get_tts(self, text: str): | ||
""" Makes request to OpenAI TTS engine to convert text into audio""" | ||
headers: dict = {"Authorization": f"Bearer {self._api_key}"} | ||
data: dict = {"model": self._model, "input": text, "voice": self._voice, "speed": self._speed} | ||
headers: dict = {"Authorization": f"Bearer {self._api_key}"} if self._api_key else {} | ||
data: dict = { | ||
"model": self._model, | ||
"input": text, | ||
"voice": self._voice, | ||
"response_format": "wav", | ||
"speed": self._speed | ||
} | ||
return requests.post(self._url, headers=headers, json=data) | ||
|
||
@staticmethod | ||
def get_supported_langs() -> list: | ||
"""Returns list of supported languages. Note: the model determines the provides language automatically.""" | ||
return ["af", "ar", "hy", "az", "be", "bs", "bg", "ca", "zh", "hr", "cs", "da", "nl", "en", "et", "fi", "fr", "gl", "de", "el", "he", "hi", "hu", "is", "id", "it", "ja", "kn", "kk", "ko", "lv", "lt", "mk", "ms", "mr", "mi", "ne", "no", "fa", "pl", "pt", "ro", "ru", "sr", "sk", "sl", "es", "sw", "sv", "tl", "ta", "th", "tr", "uk", "ur", "vi", "cy"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"config": { | ||
"step": { | ||
"user": { | ||
"title": "Füge eine Text zu Sprache Engine hinzu", | ||
"description": "Gib Konfigurationsdaten ein. Schau in die Dokumentation für weitere Informationen.", | ||
"data": { | ||
"api_key": "Gib den OpenAI API Schlüssel ein.", | ||
"speed": "Gib die Geschwindigkeit der Sprache ein", | ||
"model": "Wähle das zu verwendende Modell.", | ||
"voice": "Wähle eine Stimme.", | ||
"url": "Gib den OpenAI-kompatiblen Endpunkt ein. Optional kann eine Portnummer angegeben werden." | ||
} | ||
} | ||
}, | ||
"error": { | ||
"wrong_api_key": "Ungültiger API Schlüssel. Bitte gib einen gültigen API Schlüssel ein.", | ||
"already_configured": "Diese Stimme und Endpunkt sind bereits konfiguriert." | ||
}, | ||
"abort": { | ||
"already_configured": "Diese Stimme und Endpunkt sind bereits konfiguriert." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"name": "OpenAI TTS Speech Service", | ||
"homeassistant": "2024.5.3", | ||
"render_readme": true | ||
"render_readme": true, | ||
"version": "0.2.3" | ||
} |