- NEW: User preferences for STT model and TTS voice - Database: stt_model and tts_voice columns in users table - UI: Voice Preferences section in Settings with dropdowns - API: /api/user/preferences (GET/POST) + /preferences/options - Transcribe: Respects user's STT model (Google, LiteLLM) - TTS: Respects user's TTS voice (Google, LiteLLM, OpenAI, ElevenLabs) - Preview: Test TTS voice before saving - Available models/voices auto-detected from provider config
45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
// ============================================================
|
|
// TRANSCRIBE GOOGLE — Vertex AI / Gemini audio transcription
|
|
// Sends audio inline to Gemini which returns spoken text.
|
|
// Supports: gemini-2.0-flash (default), gemini-2.5-flash
|
|
// Requires: GOOGLE_VERTEX_PROJECT, @google-cloud/vertexai installed
|
|
// ============================================================
|
|
|
|
async function transcribeWithGemini(buffer, mimeType, modelName) {
|
|
var VertexModule = require('@google-cloud/vertexai');
|
|
var project = process.env.GOOGLE_VERTEX_PROJECT;
|
|
var location = process.env.GOOGLE_VERTEX_LOCATION || 'us-central1';
|
|
if (!project) throw new Error('GOOGLE_VERTEX_PROJECT not set');
|
|
|
|
var vertex = new VertexModule.VertexAI({ project: project, location: location });
|
|
var model = vertex.getGenerativeModel({
|
|
model: modelName || process.env.GOOGLE_STT_MODEL || 'gemini-2.0-flash'
|
|
});
|
|
|
|
var base64 = buffer.toString('base64');
|
|
var safeMime = mimeType || 'audio/webm';
|
|
|
|
var result = await model.generateContent({
|
|
contents: [{
|
|
role: 'user',
|
|
parts: [
|
|
{ inlineData: { mimeType: safeMime, data: base64 } },
|
|
{ text: 'Transcribe this audio. Output the spoken words only, exactly as heard. No commentary, no formatting, no explanation.' }
|
|
]
|
|
}]
|
|
});
|
|
|
|
var text = '';
|
|
if (result.response && result.response.candidates && result.response.candidates[0]) {
|
|
var parts = result.response.candidates[0].content.parts || [];
|
|
parts.forEach(function(p) { if (p.text) text += p.text; });
|
|
}
|
|
return text.trim();
|
|
}
|
|
|
|
function isGoogleSTTConfigured() {
|
|
if (!process.env.GOOGLE_VERTEX_PROJECT) return false;
|
|
try { require('@google-cloud/vertexai'); return true; } catch(e) { return false; }
|
|
}
|
|
|
|
module.exports = { transcribeWithGemini, isGoogleSTTConfigured };
|