UNPKG

mastra-browser-core

Version:

The core foundation of the Mastra framework, providing essential components and interfaces for building AI-powered applications.

260 lines (256 loc) 8.14 kB
'use strict'; var chunkXXM463NA_cjs = require('../chunk-XXM463NA.cjs'); var chunkSUWCCDLE_cjs = require('../chunk-SUWCCDLE.cjs'); var chunk7D636BPD_cjs = require('../chunk-7D636BPD.cjs'); // src/voice/voice.ts var _MastraVoice_decorators, _init, _a; _MastraVoice_decorators = [chunkXXM463NA_cjs.InstrumentClass({ prefix: "voice", excludeMethods: ["__setTools", "__setLogger", "__setTelemetry", "#log"] })]; var _MastraVoice = class _MastraVoice extends (_a = chunkSUWCCDLE_cjs.MastraBase) { constructor({ listeningModel, speechModel, speaker, realtimeConfig, name } = {}) { super({ component: "VOICE", name }); chunk7D636BPD_cjs.__publicField(this, "listeningModel"); chunk7D636BPD_cjs.__publicField(this, "speechModel"); chunk7D636BPD_cjs.__publicField(this, "speaker"); chunk7D636BPD_cjs.__publicField(this, "realtimeConfig"); this.listeningModel = listeningModel; this.speechModel = speechModel; this.speaker = speaker; this.realtimeConfig = realtimeConfig; } traced(method, methodName) { return this.telemetry?.traceMethod(method, { spanName: `voice.${methodName}`, attributes: { "voice.type": this.speechModel?.name || this.listeningModel?.name || "unknown" } }) ?? method; } updateConfig(_options) { this.logger.warn("updateConfig not implemented by this voice provider"); } /** * Initializes a WebSocket or WebRTC connection for real-time communication * @returns Promise that resolves when the connection is established */ connect(_options) { this.logger.warn("connect not implemented by this voice provider"); return Promise.resolve(); } /** * Relay audio data to the voice provider for real-time processing * @param audioData Audio data to relay */ send(_audioData) { this.logger.warn("relay not implemented by this voice provider"); return Promise.resolve(); } /** * Trigger voice providers to respond */ answer(_options) { this.logger.warn("answer not implemented by this voice provider"); return Promise.resolve(); } /** * Equip the voice provider with instructions * @param instructions Instructions to add */ addInstructions(_instructions) { this.logger.warn("addInstructions not implemented by this voice provider"); } /** * Equip the voice provider with tools * @param tools Array of tools to add */ addTools(_tools) { this.logger.warn("addTools not implemented by this voice provider"); } /** * Disconnect from the WebSocket or WebRTC connection */ close() { this.logger.warn("close not implemented by this voice provider"); } /** * Register an event listener * @param event Event name (e.g., 'speaking', 'writing', 'error') * @param callback Callback function that receives event data */ on(_event, _callback) { this.logger.warn("on not implemented by this voice provider"); } /** * Remove an event listener * @param event Event name (e.g., 'speaking', 'writing', 'error') * @param callback Callback function to remove */ off(_event, _callback) { this.logger.warn("off not implemented by this voice provider"); } /** * Get available speakers/voices * @returns Array of available voice IDs and their metadata */ getSpeakers() { this.logger.warn("getSpeakers not implemented by this voice provider"); return Promise.resolve([]); } }; _MastraVoice = /*@__PURE__*/(_ => { _init = chunk7D636BPD_cjs.__decoratorStart(_a); _MastraVoice = chunk7D636BPD_cjs.__decorateElement(_init, 0, "MastraVoice", _MastraVoice_decorators, _MastraVoice); chunk7D636BPD_cjs.__name(_MastraVoice, "MastraVoice"); return _MastraVoice; })(); chunk7D636BPD_cjs.__runInitializers(_init, 1, _MastraVoice); var MastraVoice = _MastraVoice; // src/voice/composite-voice.ts var _CompositeVoice = class _CompositeVoice extends MastraVoice { constructor({ speakProvider, listenProvider, realtimeProvider }) { super(); chunk7D636BPD_cjs.__publicField(this, "speakProvider"); chunk7D636BPD_cjs.__publicField(this, "listenProvider"); chunk7D636BPD_cjs.__publicField(this, "realtimeProvider"); this.speakProvider = speakProvider; this.listenProvider = listenProvider; this.realtimeProvider = realtimeProvider; } /** * Convert text to speech using the configured provider * @param input Text or text stream to convert to speech * @param options Speech options including speaker and provider-specific options * @returns Audio stream or void if in realtime mode */ async speak(input, options) { if (this.realtimeProvider) { return this.realtimeProvider.speak(input, options); } else if (this.speakProvider) { return this.speakProvider.speak(input, options); } throw new Error("No speak provider or realtime provider configured"); } async listen(audioStream, options) { if (this.realtimeProvider) { return await this.realtimeProvider.listen(audioStream, options); } else if (this.listenProvider) { return await this.listenProvider.listen(audioStream, options); } throw new Error("No listen provider or realtime provider configured"); } async getSpeakers() { if (this.realtimeProvider) { return this.realtimeProvider.getSpeakers(); } else if (this.speakProvider) { return this.speakProvider.getSpeakers(); } throw new Error("No speak provider or realtime provider configured"); } updateConfig(options) { if (!this.realtimeProvider) { return; } this.realtimeProvider.updateConfig(options); } /** * Initializes a WebSocket or WebRTC connection for real-time communication * @returns Promise that resolves when the connection is established */ connect(options) { if (!this.realtimeProvider) { throw new Error("No realtime provider configured"); } return this.realtimeProvider.connect(options); } /** * Relay audio data to the voice provider for real-time processing * @param audioData Audio data to send */ send(audioData) { if (!this.realtimeProvider) { throw new Error("No realtime provider configured"); } return this.realtimeProvider.send(audioData); } /** * Trigger voice providers to respond */ answer(options) { if (!this.realtimeProvider) { throw new Error("No realtime provider configured"); } return this.realtimeProvider.answer(options); } /** * Equip the voice provider with instructions * @param instructions Instructions to add */ addInstructions(instructions) { if (!this.realtimeProvider) { return; } this.realtimeProvider.addInstructions(instructions); } /** * Equip the voice provider with tools * @param tools Array of tools to add */ addTools(tools) { if (!this.realtimeProvider) { return; } this.realtimeProvider.addTools(tools); } /** * Disconnect from the WebSocket or WebRTC connection */ close() { if (!this.realtimeProvider) { throw new Error("No realtime provider configured"); } this.realtimeProvider.close(); } /** * Register an event listener * @param event Event name (e.g., 'speaking', 'writing', 'error') * @param callback Callback function that receives event data */ on(event, callback) { if (!this.realtimeProvider) { throw new Error("No realtime provider configured"); } this.realtimeProvider.on(event, callback); } /** * Remove an event listener * @param event Event name (e.g., 'speaking', 'writing', 'error') * @param callback Callback function to remove */ off(event, callback) { if (!this.realtimeProvider) { throw new Error("No realtime provider configured"); } this.realtimeProvider.off(event, callback); } }; chunk7D636BPD_cjs.__name(_CompositeVoice, "CompositeVoice"); var CompositeVoice = _CompositeVoice; exports.CompositeVoice = CompositeVoice; exports.MastraVoice = MastraVoice; //# sourceMappingURL=index.cjs.map //# sourceMappingURL=index.cjs.map