@hamsa-ai/voice-agents-sdk 0.3.1 → 0.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +0,0 @@
1
- /*!
2
- * The buffer module from node.js, for the browser.
3
- *
4
- * @author Feross Aboukhadijeh <https://feross.org>
5
- * @license MIT
6
- */
7
-
8
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -1,8 +0,0 @@
1
- /*!
2
- * The buffer module from node.js, for the browser.
3
- *
4
- * @author Feross Aboukhadijeh <https://feross.org>
5
- * @license MIT
6
- */
7
-
8
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -1,8 +0,0 @@
1
- /*!
2
- * The buffer module from node.js, for the browser.
3
- *
4
- * @author Feross Aboukhadijeh <https://feross.org>
5
- * @license MIT
6
- */
7
-
8
- /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -1,8 +0,0 @@
1
- declare class AudioPlayerProcessor {
2
- audioData: any[];
3
- isPaused: boolean;
4
- marks: any[];
5
- isDone: boolean;
6
- clearAllData(): void;
7
- process(inputs: any, outputs: any): boolean;
8
- }
@@ -1,4 +0,0 @@
1
- declare class AudioProcessor {
2
- encodeBase64(bytes: any): string;
3
- process(inputs: any, outputs: any, parameters: any): boolean;
4
- }
@@ -1,67 +0,0 @@
1
- export default class AudioPlayer {
2
- /**
3
- * Constructs a new AudioPlayer instance.
4
- * @param {WebSocket} ws - The WebSocket connection.
5
- * @param {function} onSpeaking - Callback when speaking starts.
6
- * @param {function} onListening - Callback when listening starts.
7
- * @param {function} onStreamReady - Callback when MediaStream is ready.
8
- */
9
- constructor(ws: WebSocket, onSpeaking: Function, onListening: Function, onStreamReady: Function);
10
- audioContext: any;
11
- ws: WebSocket;
12
- isPaused: boolean;
13
- onSpeakingCB: Function;
14
- onListeningCB: Function;
15
- isPlaying: boolean;
16
- gainNode: any;
17
- mediaStreamDestination: any;
18
- onStreamReady: Function;
19
- /**
20
- * Initializes the AudioWorklet and sets up the processor.
21
- */
22
- initAudioWorklet(): Promise<void>;
23
- processor: AudioWorkletNode;
24
- /**
25
- * Enqueues audio data to be played.
26
- * @param {string} base64Data - Base64 encoded PCM16 audio data.
27
- */
28
- enqueueAudio(base64Data: string): void;
29
- /**
30
- * Pauses audio playback.
31
- */
32
- pause(): void;
33
- /**
34
- * Resumes audio playback.
35
- */
36
- resume(): void;
37
- /**
38
- * Stops audio playback and clears the buffer.
39
- */
40
- stopAndClear(): void;
41
- /**
42
- * Adds a mark to the audio stream.
43
- * @param {string} markName - Name of the mark.
44
- */
45
- addMark(markName: string): void;
46
- /**
47
- * Converts PCM16 data to Float32.
48
- * @param {Uint8Array} pcm16Array - PCM16 audio data.
49
- * @returns {Float32Array} Float32 audio samples.
50
- */
51
- pcm16ToFloat32(pcm16Array: Uint8Array): Float32Array;
52
- /**
53
- * Updates the playing state and triggers callbacks.
54
- * @param {boolean} isPlaying - Indicates whether audio is playing.
55
- */
56
- updatePlayingState(isPlaying: boolean): void;
57
- /**
58
- * Sets the volume of the audio playback.
59
- * @param {number} volume - Volume level between 0.0 and 1.0.
60
- */
61
- setVolume(volume: number): void;
62
- /**
63
- * Returns the MediaStream capturing the audio being played.
64
- * @returns {MediaStream}
65
- */
66
- getMediaStream(): MediaStream;
67
- }
@@ -1,37 +0,0 @@
1
- export default class AudioRecorder {
2
- /**
3
- * Constructs a new AudioRecorder instance.
4
- * @param {function} onStreamReady - Callback invoked when MediaStream is ready.
5
- */
6
- constructor(onStreamReady: Function);
7
- audioContext: any;
8
- mediaStreamSource: any;
9
- audioWorkletNode: AudioWorkletNode;
10
- mediaStream: MediaStream;
11
- isPaused: boolean;
12
- mediaStreamDestination: any;
13
- onStreamReady: Function;
14
- /**
15
- * Starts streaming audio by capturing from the microphone and sending it over WebSocket.
16
- * @param {WebSocket} ws - The WebSocket connection.
17
- * @returns {Promise<void>}
18
- */
19
- startStreaming(ws: WebSocket): Promise<void>;
20
- /**
21
- * Pauses audio streaming.
22
- */
23
- pause(): void;
24
- /**
25
- * Resumes audio streaming.
26
- */
27
- resume(): void;
28
- /**
29
- * Stops audio streaming and releases resources.
30
- */
31
- stop(): void;
32
- /**
33
- * Returns the MediaStream capturing the local audio being recorded.
34
- * @returns {MediaStream | null}
35
- */
36
- getMediaStream(): MediaStream | null;
37
- }
@@ -1,115 +0,0 @@
1
- export default class WebSocketManager {
2
- /**
3
- * Constructs a new WebSocketManager instance.
4
- * @param {string} url - The WebSocket URL.
5
- * @param {string} conversationId - The conversation ID.
6
- * @param {function} onError - Callback for error events.
7
- * @param {function} onStart - Callback when the WebSocket starts.
8
- * @param {function} onTranscriptionReceived - Callback for received transcriptions.
9
- * @param {function} onAnswerReceived - Callback for received answers.
10
- * @param {function} onSpeaking - Callback when speaking starts.
11
- * @param {function} onListening - Callback when listening starts.
12
- * @param {function} onClosed - Callback when the WebSocket is closed.
13
- * @param {boolean} voiceEnablement - Flag to enable voice features.
14
- * @param {Array} tools - Array of tools/functions to be used.
15
- * @param {string} apiKey - API key for authentication.
16
- * @param {function} onRemoteStreamAvailable - Callback when remote MediaStream is available.
17
- * @param {function} onLocalStreamAvailable - Callback when local MediaStream is available.
18
- * @param {function} onInfo - Callback for info events.
19
- */
20
- constructor(url: string, conversationId: string, onError: Function, onStart: Function, onTranscriptionReceived: Function, onAnswerReceived: Function, onSpeaking: Function, onListening: Function, onClosed: Function, voiceEnablement: boolean, tools: any[], apiKey: string, onRemoteStreamAvailable: Function, onLocalStreamAvailable: Function, onInfo: Function);
21
- url: string;
22
- ws: WebSocket;
23
- isConnected: boolean;
24
- audioPlayer: AudioPlayer;
25
- audioRecorder: AudioRecorder;
26
- last_transcription_date: Date;
27
- last_voice_byte_date: Date;
28
- is_media: boolean;
29
- onErrorCB: Function;
30
- onStartCB: Function;
31
- onTranscriptionReceivedCB: Function;
32
- onAnswerReceivedCB: Function;
33
- onSpeakingCB: Function;
34
- onListeningCB: Function;
35
- onClosedCB: Function;
36
- voiceEnablement: boolean;
37
- tools: any[];
38
- apiKey: string;
39
- onRemoteStreamAvailable: Function;
40
- onLocalStreamAvailable: Function;
41
- onInfoCB: Function;
42
- /**
43
- * Sets the volume for AudioPlayer.
44
- * @param {number} volume - Volume level between 0.0 and 1.0.
45
- */
46
- setVolume(volume: number): void;
47
- /**
48
- * Initializes and starts the WebSocket connection, AudioPlayer, and AudioRecorder.
49
- */
50
- startCall(): void;
51
- /**
52
- * Handles the WebSocket 'open' event.
53
- */
54
- onOpen(): void;
55
- /**
56
- * Handles incoming WebSocket messages.
57
- * @param {MessageEvent} event - The message event.
58
- */
59
- onMessage(event: MessageEvent): void;
60
- /**
61
- * Handles the WebSocket 'close' event.
62
- * @param {CloseEvent} event - The close event.
63
- */
64
- onClose(event: CloseEvent): void;
65
- /**
66
- * Handles the WebSocket 'error' event.
67
- * @param {Event} error - The error event.
68
- */
69
- onError(error: Event): void;
70
- /**
71
- * Ends the WebSocket call, stops AudioPlayer and AudioRecorder.
72
- */
73
- endCall(): void;
74
- /**
75
- * Pauses the WebSocket call by pausing AudioPlayer and AudioRecorder.
76
- */
77
- pauseCall(): void;
78
- /**
79
- * Resumes the WebSocket call by resuming AudioPlayer and AudioRecorder.
80
- */
81
- resumeCall(): void;
82
- /**
83
- * Executes the provided tool functions, supporting both synchronous and asynchronous calls.
84
- *
85
- * This function iterates over the given array of tool objects. For each tool of type
86
- * "function", it attempts to locate the corresponding function by its name in the tools list.
87
- * The function arguments are parsed from a JSON string and passed to the function.
88
- * If the function executes successfully, its response is captured; otherwise, an error
89
- * message is returned. The results are returned in the same order as the input array.
90
- *
91
- * @param {Array} tools_array - An array of tool objects to execute. Each object should
92
- * have the following structure:
93
- * {
94
- * id: <unique identifier>,
95
- * type: "function",
96
- * function: {
97
- * name: <string>, // The function's name.
98
- * arguments: <string> // A JSON string representing the function arguments.
99
- * }
100
- * }
101
- * @returns {Promise<Array>} A promise that resolves to an array of results. Each result object has
102
- * the structure:
103
- * {
104
- * id: <tool id>,
105
- * function: {
106
- * name: <function name>,
107
- * response: <result of the function call or an error message>
108
- * }
109
- * }
110
- */
111
- run_tools(tools_array: any[]): Promise<any[]>;
112
- #private;
113
- }
114
- import AudioPlayer from './audio_player';
115
- import AudioRecorder from './audio_recorder';