minor cleanup

This commit is contained in:
uukelele-scratch 2025-04-21 08:06:19 +01:00
parent c540b7d92f
commit 76b96f829e
2 changed files with 52 additions and 52 deletions

View file

@ -1,6 +1,6 @@
import { exec, spawn } from 'child_process';
import settings from '../../settings.js';
import { Pollinations } from '../models/pollinations.js';
import { sendAudioRequest } from '../models/pollinations.js';
let speakingQueue = [];
let isSpeaking = false;
@ -20,7 +20,7 @@ async function processQueue() {
const isWin = process.platform === 'win32';
const isMac = process.platform === 'darwin';
const model = settings.speak_model || 'system';
const model = settings.speak_model || 'pollinations/openai-audio/echo';
if (model === 'system') {
// system TTS
@ -43,7 +43,11 @@ $s.Speak('${txt.replace(/'/g,"''")}'); $s.Dispose()"`
if (prov !== 'pollinations') throw new Error(`Unknown provider: ${prov}`);
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) {
const ps = `

View file

@ -61,13 +61,11 @@ export class Pollinations {
return this.sendRequest(imageMessages, systemMessage)
}
}
async sendAudioRequest(text, voice) {
const fallback = "SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU5LjI3LjEwMAAAAAAAAAAAAAAA/+NAwAAAAAAAAAAAAEluZm8AAAAPAAAAAAAAANAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAExhdmM1OS4zNwAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAAeowAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==";
// ^ 0 second silent audio clip
export async function sendAudioRequest(text, model, voice) {
const payload = {
model: this.model_name,
model: model,
modalities: ["text", "audio"],
audio: {
voice: voice,
@ -89,7 +87,7 @@ export class Pollinations {
let audioData = null;
try {
const response = await fetch(this.url, {
const response = await fetch("https://text.pollinations.ai/openai", {
method: "POST",
headers: {
"Content-Type": "application/json"
@ -99,7 +97,7 @@ export class Pollinations {
if (!response.ok) {
console.error("Failed to get text transcription. Status", response.status, (await response.text()))
return fallback
return null;
}
const result = await response.json();
@ -107,8 +105,6 @@ export class Pollinations {
return audioData;
} catch (err) {
console.error("TTS fetch failed:", err);
return fallback
return null;
}
}
}