mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-30 02:43:09 +02:00
minor cleanup
This commit is contained in:
parent
c540b7d92f
commit
76b96f829e
2 changed files with 52 additions and 52 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { exec, spawn } from 'child_process';
|
import { exec, spawn } from 'child_process';
|
||||||
import settings from '../../settings.js';
|
import settings from '../../settings.js';
|
||||||
import { Pollinations } from '../models/pollinations.js';
|
import { sendAudioRequest } from '../models/pollinations.js';
|
||||||
|
|
||||||
let speakingQueue = [];
|
let speakingQueue = [];
|
||||||
let isSpeaking = false;
|
let isSpeaking = false;
|
||||||
|
@ -20,7 +20,7 @@ async function processQueue() {
|
||||||
|
|
||||||
const isWin = process.platform === 'win32';
|
const isWin = process.platform === 'win32';
|
||||||
const isMac = process.platform === 'darwin';
|
const isMac = process.platform === 'darwin';
|
||||||
const model = settings.speak_model || 'system';
|
const model = settings.speak_model || 'pollinations/openai-audio/echo';
|
||||||
|
|
||||||
if (model === 'system') {
|
if (model === 'system') {
|
||||||
// system TTS
|
// system TTS
|
||||||
|
@ -43,7 +43,11 @@ $s.Speak('${txt.replace(/'/g,"''")}'); $s.Dispose()"`
|
||||||
if (prov !== 'pollinations') throw new Error(`Unknown provider: ${prov}`);
|
if (prov !== 'pollinations') throw new Error(`Unknown provider: ${prov}`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const audioData = await new Pollinations(mdl).sendAudioRequest(txt, voice);
|
let audioData = await sendAudioRequest(txt, mdl, voice);
|
||||||
|
if (!audioData) {
|
||||||
|
audioData = "SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU5LjI3LjEwMAAAAAAAAAAAAAAA/+NAwAAAAAAAAAAAAEluZm8AAAAPAAAAAAAAANAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAExhdmM1OS4zNwAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAeowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
|
||||||
|
// ^ 0 second silent audio clip
|
||||||
|
}
|
||||||
|
|
||||||
if (isWin) {
|
if (isWin) {
|
||||||
const ps = `
|
const ps = `
|
||||||
|
|
|
@ -61,13 +61,11 @@ export class Pollinations {
|
||||||
|
|
||||||
return this.sendRequest(imageMessages, systemMessage)
|
return this.sendRequest(imageMessages, systemMessage)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async sendAudioRequest(text, voice) {
|
export async function sendAudioRequest(text, model, voice) {
|
||||||
const fallback = "SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU5LjI3LjEwMAAAAAAAAAAAAAAA/+NAwAAAAAAAAAAAAEluZm8AAAAPAAAAAAAAANAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAExhdmM1OS4zNwAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAeowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
|
|
||||||
// ^ 0 second silent audio clip
|
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
model: this.model_name,
|
model: model,
|
||||||
modalities: ["text", "audio"],
|
modalities: ["text", "audio"],
|
||||||
audio: {
|
audio: {
|
||||||
voice: voice,
|
voice: voice,
|
||||||
|
@ -89,7 +87,7 @@ export class Pollinations {
|
||||||
let audioData = null;
|
let audioData = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(this.url, {
|
const response = await fetch("https://text.pollinations.ai/openai", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Content-Type": "application/json"
|
||||||
|
@ -99,7 +97,7 @@ export class Pollinations {
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
console.error("Failed to get text transcription. Status", response.status, (await response.text()))
|
console.error("Failed to get text transcription. Status", response.status, (await response.text()))
|
||||||
return fallback
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
|
@ -107,8 +105,6 @@ export class Pollinations {
|
||||||
return audioData;
|
return audioData;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("TTS fetch failed:", err);
|
console.error("TTS fetch failed:", err);
|
||||||
return fallback
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue