Merge pull request #2002 from Yanyutin753/addAudio

🤩 Added custom openai tts models and role variables
This commit is contained in:
Timothy Jaeryang Baek 2024-05-08 08:03:20 -07:00 committed by GitHub
commit 675328c881
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
34 changed files with 89 additions and 7 deletions

View File

@ -43,6 +43,8 @@ from config import (
DEVICE_TYPE,
AUDIO_OPENAI_API_BASE_URL,
AUDIO_OPENAI_API_KEY,
AUDIO_OPENAI_API_MODEL,
AUDIO_OPENAI_API_VOICE,
)
log = logging.getLogger(__name__)
@ -60,6 +62,8 @@ app.add_middleware(
app.state.OPENAI_API_BASE_URL = AUDIO_OPENAI_API_BASE_URL
app.state.OPENAI_API_KEY = AUDIO_OPENAI_API_KEY
app.state.OPENAI_API_MODEL = AUDIO_OPENAI_API_MODEL
app.state.OPENAI_API_VOICE = AUDIO_OPENAI_API_VOICE
# setting device type for whisper model
whisper_device_type = DEVICE_TYPE if DEVICE_TYPE and DEVICE_TYPE == "cuda" else "cpu"
@ -72,6 +76,8 @@ SPEECH_CACHE_DIR.mkdir(parents=True, exist_ok=True)
class OpenAIConfigUpdateForm(BaseModel):
url: str
key: str
model: str
speaker: str
@app.get("/config")
@ -79,6 +85,8 @@ async def get_openai_config(user=Depends(get_admin_user)):
return {
"OPENAI_API_BASE_URL": app.state.OPENAI_API_BASE_URL,
"OPENAI_API_KEY": app.state.OPENAI_API_KEY,
"OPENAI_API_MODEL": app.state.OPENAI_API_MODEL,
"OPENAI_API_VOICE": app.state.OPENAI_API_VOICE,
}
@ -91,11 +99,15 @@ async def update_openai_config(
app.state.OPENAI_API_BASE_URL = form_data.url
app.state.OPENAI_API_KEY = form_data.key
app.state.OPENAI_API_MODEL = form_data.model
app.state.OPENAI_API_VOICE = form_data.speaker
return {
"status": True,
"OPENAI_API_BASE_URL": app.state.OPENAI_API_BASE_URL,
"OPENAI_API_KEY": app.state.OPENAI_API_KEY,
"OPENAI_API_MODEL": app.state.OPENAI_API_MODEL,
"OPENAI_API_VOICE": app.state.OPENAI_API_VOICE,
}

View File

@ -586,6 +586,8 @@ IMAGE_GENERATION_MODEL = os.getenv("IMAGE_GENERATION_MODEL", "")
AUDIO_OPENAI_API_BASE_URL = os.getenv("AUDIO_OPENAI_API_BASE_URL", OPENAI_API_BASE_URL)
AUDIO_OPENAI_API_KEY = os.getenv("AUDIO_OPENAI_API_KEY", OPENAI_API_KEY)
AUDIO_OPENAI_API_MODEL = os.getenv("AUDIO_OPENAI_API_MODEL", "tts-1")
AUDIO_OPENAI_API_VOICE = os.getenv("AUDIO_OPENAI_API_VOICE", "alloy")
####################################
# LiteLLM

View File

@ -30,6 +30,8 @@ export const getAudioConfig = async (token: string) => {
type OpenAIConfigForm = {
url: string;
key: string;
model: string;
speaker: string;
};
export const updateAudioConfig = async (token: string, payload: OpenAIConfigForm) => {
@ -95,7 +97,8 @@ export const transcribeAudio = async (token: string, file: File) => {
export const synthesizeOpenAISpeech = async (
token: string = '',
speaker: string = 'alloy',
text: string = ''
text: string = '',
model: string = 'tts-1'
) => {
let error = null;
@ -106,7 +109,7 @@ export const synthesizeOpenAISpeech = async (
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'tts-1',
model: model,
input: text,
voice: speaker
})

View File

@ -239,7 +239,8 @@ export const generateOpenAIChatCompletion = async (
export const synthesizeOpenAISpeech = async (
token: string = '',
speaker: string = 'alloy',
text: string = ''
text: string = '',
model: string = 'tts-1'
) => {
let error = null;
@ -250,7 +251,7 @@ export const synthesizeOpenAISpeech = async (
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'tts-1',
model: model,
input: text,
voice: speaker
})

View File

@ -227,7 +227,8 @@
const res = await synthesizeOpenAISpeech(
localStorage.token,
$settings?.audio?.speaker,
sentence
sentence,
$settings?.audio?.model
).catch((error) => {
toast.error(error);

View File

@ -26,6 +26,8 @@
let voices = [];
let speaker = '';
let models = [];
let model = '';
const getOpenAIVoices = () => {
voices = [
@ -38,6 +40,10 @@
];
};
const getOpenAIVoicesModel = () => {
models = [{ name: 'tts-1' }, { name: 'tts-1-hd' }];
};
const getWebAPIVoices = () => {
const getVoicesLoop = setInterval(async () => {
voices = await speechSynthesis.getVoices();
@ -78,12 +84,16 @@
if (TTSEngine === 'openai') {
const res = await updateAudioConfig(localStorage.token, {
url: OpenAIUrl,
key: OpenAIKey
key: OpenAIKey,
model: model,
speaker: speaker
});
if (res) {
OpenAIUrl = res.OPENAI_API_BASE_URL;
OpenAIKey = res.OPENAI_API_KEY;
model = res.OPENAI_API_MODEL;
speaker = res.OPENAI_API_VOICE;
}
}
};
@ -98,9 +108,11 @@
STTEngine = settings?.audio?.STTEngine ?? '';
TTSEngine = settings?.audio?.TTSEngine ?? '';
speaker = settings?.audio?.speaker ?? '';
model = settings?.audio?.model ?? '';
if (TTSEngine === 'openai') {
getOpenAIVoices();
getOpenAIVoicesModel();
} else {
getWebAPIVoices();
}
@ -111,6 +123,8 @@
if (res) {
OpenAIUrl = res.OPENAI_API_BASE_URL;
OpenAIKey = res.OPENAI_API_KEY;
model = res.OPENAI_API_MODEL;
speaker = res.OPENAI_API_VOICE;
}
}
});
@ -126,7 +140,8 @@
audio: {
STTEngine: STTEngine !== '' ? STTEngine : undefined,
TTSEngine: TTSEngine !== '' ? TTSEngine : undefined,
speaker: speaker !== '' ? speaker : undefined
speaker: speaker !== '' ? speaker : undefined,
model: model !== '' ? model : undefined
}
});
dispatch('save');
@ -215,6 +230,7 @@
if (e.target.value === 'openai') {
getOpenAIVoices();
speaker = 'alloy';
model = 'tts-1';
} else {
getWebAPIVoices();
speaker = '';
@ -307,6 +323,25 @@
</div>
</div>
</div>
<div>
<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Set Model')}</div>
<div class="flex w-full">
<div class="flex-1">
<input
list="model-list"
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
bind:value={model}
placeholder="Select a model"
/>
<datalist id="model-list">
{#each models as model}
<option value={model.name} />
{/each}
</datalist>
</div>
</div>
</div>
{/if}
</div>

View File

@ -391,6 +391,7 @@
"Set Steps": "ضبط الخطوات",
"Set Title Auto-Generation Model": "قم بتعيين نموذج إنشاء العنوان تلقائيًا",
"Set Voice": "ضبط الصوت",
"Set Model": "ضبط النموذج",
"Settings": "الاعدادات",
"Settings saved successfully!": "تم حفظ الاعدادات بنجاح",
"Share": "كشاركة",

View File

@ -391,6 +391,7 @@
"Set Steps": "Задай Стъпки",
"Set Title Auto-Generation Model": "Задай Модел за Автоматично Генериране на Заглавие",
"Set Voice": "Задай Глас",
"Set Model": "Задай Модел",
"Settings": "Настройки",
"Settings saved successfully!": "Настройките са запазени успешно!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "পরবর্তী ধাপসমূহ",
"Set Title Auto-Generation Model": "শিরোনাম অটোজেনারেশন মডেন নির্ধারণ করুন",
"Set Voice": "কন্ঠস্বর নির্ধারণ করুন",
"Set Model": "মডেল নির্ধারণ করুন",
"Settings": "সেটিংসমূহ",
"Settings saved successfully!": "সেটিংগুলো সফলভাবে সংরক্ষিত হয়েছে",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Estableix Passos",
"Set Title Auto-Generation Model": "Estableix Model d'Auto-Generació de Títol",
"Set Voice": "Estableix Veu",
"Set Model": "Estableix Model",
"Settings": "Configuracions",
"Settings saved successfully!": "Configuracions guardades amb èxit!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Schritte festlegen",
"Set Title Auto-Generation Model": "Modell für automatische Titelgenerierung festlegen",
"Set Voice": "Stimme festlegen",
"Set Model": "Modell festlegen",
"Settings": "Einstellungen",
"Settings saved successfully!": "Einstellungen erfolgreich gespeichert!",
"Share": "Teilen",

View File

@ -391,6 +391,7 @@
"Set Steps": "Set Steps so many steps",
"Set Title Auto-Generation Model": "Set Title Auto-Generation Model very auto-generate",
"Set Voice": "Set Voice so speak",
"Set Model": "Set Model so speak",
"Settings": "Settings much settings",
"Settings saved successfully!": "Settings saved successfully! Very success!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "",
"Set Title Auto-Generation Model": "",
"Set Voice": "",
"Set Model": "",
"Settings": "",
"Settings saved successfully!": "",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "",
"Set Title Auto-Generation Model": "",
"Set Voice": "",
"Set Model": "",
"Settings": "",
"Settings saved successfully!": "",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Establecer Pasos",
"Set Title Auto-Generation Model": "Establecer modelo de generación automática de títulos",
"Set Voice": "Establecer la voz",
"Set Model": "Establecer el modelo",
"Settings": "Configuración",
"Settings saved successfully!": "¡Configuración guardada exitosamente!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "تنظیم گام\u200cها",
"Set Title Auto-Generation Model": "تنظیم مدل تولید خودکار عنوان",
"Set Voice": "تنظیم صدا",
"Set Model": "تنظیم مدل",
"Settings": "تنظیمات",
"Settings saved successfully!": "تنظیمات با موفقیت ذخیره شد!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Définir les étapes",
"Set Title Auto-Generation Model": "Définir le modèle de génération automatique de titre",
"Set Voice": "Définir la voix",
"Set Model": "Configurer le modèle",
"Settings": "Paramètres",
"Settings saved successfully!": "Paramètres enregistrés avec succès !",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Définir les étapes",
"Set Title Auto-Generation Model": "Définir le modèle de génération automatique de titre",
"Set Voice": "Définir la voix",
"Set Model": "Définir le modèle",
"Settings": "Paramètres",
"Settings saved successfully!": "Paramètres enregistrés avec succès !",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Imposta passaggi",
"Set Title Auto-Generation Model": "Imposta modello di generazione automatica del titolo",
"Set Voice": "Imposta voce",
"Set Model": "Imposta modello",
"Settings": "Impostazioni",
"Settings saved successfully!": "Impostazioni salvate con successo!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "ステップを設定",
"Set Title Auto-Generation Model": "タイトル自動生成モデルを設定",
"Set Voice": "音声を設定",
"Set Model": "モデルを設定",
"Settings": "設定",
"Settings saved successfully!": "設定が正常に保存されました!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "ნაბიჯების დაყენება",
"Set Title Auto-Generation Model": "სათაურის ავტომატური გენერაციის მოდელის დაყენება",
"Set Voice": "ხმის დაყენება",
"Set Model": "მოდელის დაყენება",
"Settings": "ხელსაწყოები",
"Settings saved successfully!": "პარამეტრები წარმატებით განახლდა!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "단계 설정",
"Set Title Auto-Generation Model": "제목 자동 생성 모델 설정",
"Set Voice": "음성 설정",
"Set Model": "모델 설정",
"Settings": "설정",
"Settings saved successfully!": "설정이 성공적으로 저장되었습니다!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Stel Stappen in",
"Set Title Auto-Generation Model": "Stel Titel Auto-Generatie Model in",
"Set Voice": "Stel Stem in",
"Set Model": "Stel die model op",
"Settings": "Instellingen",
"Settings saved successfully!": "Instellingen succesvol opgeslagen!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Ustaw kroki",
"Set Title Auto-Generation Model": "Ustaw model automatycznego generowania tytułów",
"Set Voice": "Ustaw głos",
"Set Model": "Ustaw model",
"Settings": "Ustawienia",
"Settings saved successfully!": "Ustawienia zapisane pomyślnie!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Definir Etapas",
"Set Title Auto-Generation Model": "Definir Modelo de Geração Automática de Título",
"Set Voice": "Definir Voz",
"Set Model": "Definir Modelo",
"Settings": "Configurações",
"Settings saved successfully!": "Configurações salvas com sucesso!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Definir Etapas",
"Set Title Auto-Generation Model": "Definir Modelo de Geração Automática de Título",
"Set Voice": "Definir Voz",
"Set Model": "Definir Modelo",
"Settings": "Configurações",
"Settings saved successfully!": "Configurações salvas com sucesso!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Установить шаги",
"Set Title Auto-Generation Model": "Установить модель автогенерации заголовков",
"Set Voice": "Установить голос",
"Set Model": "Установить модель",
"Settings": "Настройки",
"Settings saved successfully!": "Настройки успешно сохранены!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Ange steg",
"Set Title Auto-Generation Model": "Ange modell för automatisk generering av titel",
"Set Voice": "Ange röst",
"Set Model": "Ställ in modell",
"Settings": "Inställningar",
"Settings saved successfully!": "Inställningar sparades framgångsrikt!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Adımları Ayarla",
"Set Title Auto-Generation Model": "Otomatik Başlık Oluşturma Modelini Ayarla",
"Set Voice": "Ses Ayarla",
"Set Model": "Model Ayarla",
"Settings": "Ayarlar",
"Settings saved successfully!": "Ayarlar başarıyla kaydedildi!",
"Share": "Paylaş",

View File

@ -391,6 +391,7 @@
"Set Steps": "Встановити кроки",
"Set Title Auto-Generation Model": "Встановити модель автогенерації заголовків",
"Set Voice": "Встановити голос",
"Set Model": "Встановити модель",
"Settings": "Налаштування",
"Settings saved successfully!": "Налаштування успішно збережено!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "Đặt Số Bước",
"Set Title Auto-Generation Model": "Đặt tiêu đề tự động",
"Set Voice": "Đặt Giọng nói",
"Set Model": "Thiết lập mô hình",
"Settings": "Cài đặt",
"Settings saved successfully!": "Cài đặt đã được lưu thành công!",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "设置步骤",
"Set Title Auto-Generation Model": "设置标题自动生成模型",
"Set Voice": "设置声音",
"Set Model": "设置模型",
"Settings": "设置",
"Settings saved successfully!": "设置已保存",
"Share": "",

View File

@ -391,6 +391,7 @@
"Set Steps": "設定步數",
"Set Title Auto-Generation Model": "設定自動生成標題用模型",
"Set Voice": "設定語音",
"Set Model": "設定模型",
"Settings": "設定",
"Settings saved successfully!": "成功儲存設定",
"Share": "",

View File

@ -102,6 +102,7 @@ type AudioSettings = {
STTEngine?: string;
TTSEngine?: string;
speaker?: string;
model?: string;
};
type TitleSettings = {