mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-09-30 15:16:38 +08:00
- Refactored audio handling by separating concerns into AudioAnalyzer and AudioPlayback classes. - Improved type definitions for Tauri commands and dialog interfaces in global.d.ts. - Added new CodeActions and CodePreview components to enhance code display and interaction in markdown.tsx. - Updated state management in sd.ts to include drawing functionality. - Cleaned up global styles in globals.scss, reducing complexity and improving maintainability.
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
class AudioAnalyzer {
|
|
private analyser: AnalyserNode;
|
|
private analyserData: Uint8Array;
|
|
|
|
constructor(context: AudioContext) {
|
|
this.analyser = new AnalyserNode(context, { fftSize: 256 });
|
|
this.analyserData = new Uint8Array(this.analyser.frequencyBinCount);
|
|
}
|
|
|
|
getByteFrequencyData() {
|
|
this.analyser.getByteFrequencyData(this.analyserData);
|
|
return this.analyserData;
|
|
}
|
|
|
|
getNode() {
|
|
return this.analyser;
|
|
}
|
|
}
|
|
|
|
class AudioPlayback {
|
|
private nextPlayTime: number = 0;
|
|
private isPlaying: boolean = false;
|
|
private playbackQueue: AudioBufferSourceNode[] = [];
|
|
private playBuffer: Int16Array[] = [];
|
|
|
|
// Add playback related methods
|
|
}
|
|
|
|
export class AudioHandler {
|
|
private context: AudioContext;
|
|
private mergeNode: ChannelMergerNode;
|
|
private analyzer: AudioAnalyzer;
|
|
private playback: AudioPlayback;
|
|
|
|
constructor() {
|
|
this.context = new AudioContext({ sampleRate: 24000 });
|
|
this.mergeNode = new ChannelMergerNode(this.context, { numberOfInputs: 2 });
|
|
this.analyzer = new AudioAnalyzer(this.context);
|
|
this.playback = new AudioPlayback();
|
|
|
|
this.mergeNode.connect(this.analyzer.getNode());
|
|
}
|
|
|
|
// ... rest of the implementation
|
|
}
|