/// import type { WaveProps } from '../SoundWave'; import type { AudioFormat } from './audioHelper'; /** * 录音模式类型 * - input: 按住说话模式 * - button: 点击切换模式 */ export type AudioInputMode = 'input' | 'button'; /** * 录音状态类型 */ export type RecordingState = 'idle' | 'recording' | 'willCancel'; /** * AudioInput 组件基础属性 */ export interface AudioInputBaseProps { /** * 录音模式:input-按住说话模式,button-点击切换模式 * @type { AudioInputMode } * @default 'input' */ mode?: AudioInputMode; /** * 按住文案(input 模式使用) * @type { string } * @default '按住 说话' */ pressText?: string; /** * 音频变化回调,返回录音的 Blob 对象 */ onChange?: (value: Blob) => void; /** * 隐藏功能项的回调 * @type { (isRecording: boolean) => void } * @default undefined */ onRecordingChange?: (isRecording: boolean) => void; /** * 提示文案变化回调(input 模式使用) * @type { (hint: string, isWarning: boolean) => void } * @default undefined */ onHintChange?: (hint: string, isWarning: boolean) => void; /** * 录音状态变化回调(input 模式使用) * @type { (state: RecordingState) => void } * @default undefined */ onRecordingStateChange?: (state: RecordingState) => void; /** * 音波条配置 * @type { WaveProps } * @default undefined */ waveProps?: WaveProps; /** * 自定义类名 * @type { string } * @default undefined */ waveContainerClassName?: string; /** * 音频流变化回调,用于在父组件中渲染光圈 * @type { (stream: MediaStream | null) => void } * @default undefined */ onStreamChange?: (stream: MediaStream | null) => void; /** * 是否显示光圈效果(仅 input 模式有效),默认 true * @type { boolean } * @default true */ showHalo?: boolean; /** * 自定义样式 * @type { React.CSSProperties } * @default undefined */ style?: React.CSSProperties; /** * 音频输出格式 * @description 指定录音输出的音频格式,不同浏览器支持的格式可能不同,组件会自动降级到浏览器支持的格式 * @type { AudioFormat } * @default 'webm' */ audioFormat?: AudioFormat; /** * 震动回调(input 模式使用) * @description 在进入倒计时阶段和倒计时结束时触发,用户可自定义震动行为(如 iOS 触觉反馈) * @type { (type: 'countdown' | 'timeout') => void } * @default 使用 navigator.vibrate */ onVibrate?: (type: 'countdown' | 'timeout') => void; /** * 录音中提示文案(input 模式使用) * @type { string } * @default '松手发送,上移取消' */ recordingText?: string; /** * 取消提示文案(input 模式使用) * @type { string } * @default '松开取消' */ cancelText?: string; /** * 倒计时提示文案(input 模式使用) * @description 支持 {seconds} 占位符,会替换为剩余秒数 * @type { string } * @default '{seconds}s后将停止录音' */ countdownText?: string; } /** * AudioInput 组件属性 * @description 支持直接传入各属性,或通过 allowAudio 传入配置对象 */ export interface AudioInputProps extends AudioInputBaseProps { /** * 允许音频输入的配置 * @description 可以是 boolean(启用默认配置)或 AudioInputBaseProps 对象(自定义配置) * @type { boolean | AudioInputBaseProps } * @default undefined */ allowAudio?: boolean | AudioInputBaseProps; }