| | |
| | | import { textToAudioStream } from '@/service/share' |
| | | |
| | | declare global { |
| | | // eslint-disable-next-line ts/consistent-type-definitions |
| | | // eslint-disable-next-line @typescript-eslint/consistent-type-definitions |
| | | interface Window { |
| | | ManagedMediaSource: any |
| | | } |
| | |
| | | isLoadData = false |
| | | url: string |
| | | isPublic: boolean |
| | | callback: ((event: string) => void) | null |
| | | callback: ((event: string) => {}) | null |
| | | |
| | | constructor(streamUrl: string, isPublic: boolean, msgId: string | undefined, msgContent: string | null | undefined, voice: string | undefined, callback: ((event: string) => void) | null) { |
| | | constructor(streamUrl: string, isPublic: boolean, msgId: string | undefined, msgContent: string | null | undefined, voice: string | undefined, callback: ((event: string) => {}) | null) { |
| | | this.audioContext = new AudioContext() |
| | | this.msgId = msgId |
| | | this.msgContent = msgContent |
| | |
| | | }) |
| | | } |
| | | |
| | | public setCallback(callback: ((event: string) => void) | null) { |
| | | public setCallback(callback: ((event: string) => {}) | null) { |
| | | this.callback = callback |
| | | if (callback) { |
| | | this.audio.addEventListener('ended', () => { |
| | |
| | | this.receiveAudioData(value) |
| | | } |
| | | } |
| | | catch { |
| | | catch (error) { |
| | | this.isLoadData = false |
| | | this.callback && this.callback('error') |
| | | } |
| | |
| | | this.audioContext.suspend() |
| | | } |
| | | |
| | | private cancer() { |
| | | |
| | | } |
| | | |
| | | private receiveAudioData(unit8Array: Uint8Array) { |
| | | if (!unit8Array) { |
| | | this.finishStream() |