UNPKG

@coze/uniapp-api

Version:

Official Coze UniApp SDK for seamless AI integration into your applications | 扣子官方 UniApp SDK,助您轻松集成 AI 能力到应用中

60 lines (59 loc) 2 kB
import { type ChatUpdateEvent } from '@coze/api'; import { PcmRecorder } from '../pcm-recorder'; import { WsChatEventNames } from './event-names'; import BaseWsChatClient, { type WsChatClientOptions } from './base'; export { WsChatClientOptions, WsChatEventNames }; /** * WebSocket Chat Client for WeChat Mini Program * Implements real-time chat functionality with audio support */ declare class WsChatClient extends BaseWsChatClient { recorder: PcmRecorder; private isMuted; private turnDetection; /** * Create a new WsChatClient instance * @param {any} config - Configuration options */ constructor(config: WsChatClientOptions); /** * Start recording audio and sending audio data to server * @private */ startRecord(): void; /** * Stop recording audio */ stopRecord(): void; /** * Convert ArrayBuffer to Base64 string for WeChat Mini Program * @param {ArrayBuffer} buffer - The buffer to convert * @returns {string} - Base64 string */ private arrayBufferToBase64; /** * Connect to the chat server and start recording if not muted * @param {Object} options - Connection options * @param {ChatUpdateEvent} [options.chatUpdate] - Initial chat update event * @returns {Promise<void>} - Promise that resolves when connected */ connect({ chatUpdate, }?: { chatUpdate?: Partial<ChatUpdateEvent>; }): Promise<void>; /** * Disconnect from the chat server and clean up resources * @returns {Promise<void>} - Promise that resolves when disconnected */ disconnect(): Promise<void>; /** * Enable or disable audio input * @param {boolean} enable - Whether to enable audio * @returns {Promise<void>} - Promise that resolves when the operation completes */ setAudioEnable(enable: boolean): Promise<void>; /** * Interrupt the current conversation */ interrupt(): void; } export { WsChatClient };