mirror of
				https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
				synced 2025-11-04 16:23:41 +08:00 
			
		
		
		
	feat: 添加音频上下文管理,优化 PCM 数据转换为 AudioBuffer 的实现
This commit is contained in:
		@@ -64,6 +64,7 @@ interface RequestPayload {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class QwenApi implements LLMApi {
 | 
			
		||||
  private audioContext?: AudioContext;
 | 
			
		||||
  path(path: string): string {
 | 
			
		||||
    const accessStore = useAccessStore.getState();
 | 
			
		||||
 | 
			
		||||
@@ -363,8 +364,11 @@ export class QwenApi implements LLMApi {
 | 
			
		||||
 | 
			
		||||
  // 将 PCM 字节数据转换为 AudioBuffer
 | 
			
		||||
  private convertToAudioBuffer(pcmData: Uint8Array) {
 | 
			
		||||
    const audioContext = new (window.AudioContext ||
 | 
			
		||||
      window.webkitAudioContext)();
 | 
			
		||||
    if (!this.audioContext) {
 | 
			
		||||
      this.audioContext = new (window.AudioContext ||
 | 
			
		||||
        window.webkitAudioContext)();
 | 
			
		||||
    }
 | 
			
		||||
    const audioContext = this.audioContext;
 | 
			
		||||
    const channels = 1;
 | 
			
		||||
    const sampleRate = 24000;
 | 
			
		||||
    return new Promise<AudioBuffer>((resolve, reject) => {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user