Receitas
import { VoicePipeline, WhisperCppStt, OllamaLlm, PiperTts } from 'whispa';
const pipeline = new VoicePipeline({
stt: new WhisperCppStt({ model: 'models/ggml-base.en.bin' }),
llm: new OllamaLlm({ model: 'llama3.2' }),
tts: new PiperTts({ model: 'voices/en_US-amy-medium.onnx' }),
systemPrompt: 'És um assistente de voz conciso.',
});
const { transcript, reply, audio } = await pipeline.turn('gravacao.wav');
Assistente só de texto (saltar STT/TTS)
import { VoicePipeline, MockStt, MockTts, OllamaLlm } from 'whispa';
const chat = new VoicePipeline({ stt: new MockStt(''), tts: new MockTts(), llm: new OllamaLlm({ model: 'llama3.2' }) });
const reply = await chat.respond('Resume o dia de hoje numa linha.');
Usar o teu próprio motor de LLM
import type { LlmEngine, Message } from 'whispa';
class OpenAILlm implements LlmEngine {
async chat(messages: Message[]): Promise<string> {
const res = await client.chat.completions.create({ model: 'gpt-4o-mini', messages });
return res.choices[0].message.content ?? '';
}
}
const pipeline = new VoicePipeline({ stt, llm: new OpenAILlm(), tts });
Loop push-to-talk
async function aoPremirBotao() {
const { reply, audio } = await pipeline.turn('capture.wav'); // o teu gravador escreve isto
await reproduzir(audio);
}
Limitar a memória da conversa
new VoicePipeline({ stt, llm, tts, systemPrompt: '…', maxHistory: 12 }); // mantém os últimos 12 turnos