mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-29 18:33:03 +02:00
added gpt TTS (untested)
This commit is contained in:
parent
567f3e0ab4
commit
3a960f0809
2 changed files with 39 additions and 3 deletions
|
@ -37,18 +37,29 @@ $s.Speak('${txt.replace(/'/g,"''")}'); $s.Dispose()"`
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
function getModelUrl(prov) {
|
||||||
|
if (prov === 'pollinations') {
|
||||||
|
return 'https://text.pollinations.ai/openai'
|
||||||
|
} else if (prov === 'openai') {
|
||||||
|
return 'https://api.openai.com/v1/audio/speech'
|
||||||
|
} else {
|
||||||
|
// fallback
|
||||||
|
return 'https://api.openai.com/v1/audio/speech'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// remote audio provider
|
// remote audio provider
|
||||||
let prov, mdl, voice, url;
|
let prov, mdl, voice, url;
|
||||||
if (typeof model === "string") {
|
if (typeof model === "string") {
|
||||||
[prov, mdl, voice] = model.split('/');
|
[prov, mdl, voice] = model.split('/');
|
||||||
url = "https://text.pollinations.ai/openai";
|
url = getModelUrl(prov);
|
||||||
} else {
|
} else {
|
||||||
prov = model.api;
|
prov = model.api;
|
||||||
mdl = model.model;
|
mdl = model.model;
|
||||||
voice = model.voice;
|
voice = model.voice;
|
||||||
url = model.url || "https://text.pollinations.ai/openai";
|
url = model.url || getModelUrl(prov);
|
||||||
}
|
}
|
||||||
if (prov !== 'pollinations') throw new Error(`Unknown provider: ${prov}`);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let audioData = await sendAudioRequest(txt, mdl, voice, url);
|
let audioData = await sendAudioRequest(txt, mdl, voice, url);
|
||||||
|
|
|
@ -89,5 +89,30 @@ export class GPT {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function sendAudioRequest(text, model, voice, url) {
|
||||||
|
const payload = {
|
||||||
|
model: model,
|
||||||
|
voice: voice,
|
||||||
|
input: text
|
||||||
|
}
|
||||||
|
|
||||||
|
let audioData = null;
|
||||||
|
|
||||||
|
let config = {};
|
||||||
|
|
||||||
|
if (url)
|
||||||
|
config.baseURL = url;
|
||||||
|
|
||||||
|
if (hasKey('OPENAI_ORG_ID'))
|
||||||
|
config.organization = getKey('OPENAI_ORG_ID');
|
||||||
|
|
||||||
|
config.apiKey = getKey('OPENAI_API_KEY');
|
||||||
|
|
||||||
|
openai = new OpenAIApi(config);
|
||||||
|
|
||||||
|
const mp3 = await openai.audio.speech.create(payload);
|
||||||
|
const buffer = Buffer.from(await mp3.arrayBuffer());
|
||||||
|
const base64 = buffer.toString("base64");
|
||||||
|
return base64;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue