删除无效输出
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 53s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 53s
				
			This commit is contained in:
		
							parent
							
								
									99d6cb9f9f
								
							
						
					
					
						commit
						ef15f5894e
					
				| @ -258,11 +258,11 @@ func (s *LLMService) handleStreamingResponse(req *http.Request, data map[string] | ||||
| 				initialSessage += answer | ||||
| 				if containsPunctuation(initialSessage) { | ||||
| 					segments := splitByPunctuation(initialSessage) | ||||
| 					fmt.Printf("原始文本: %s\n", initialSessage) | ||||
| 					fmt.Printf("分割后的片段数量: %d\n", len(segments)) | ||||
| 					for i, segment := range segments { | ||||
| 						fmt.Printf("片段 %d: %s\n", i+1, segment) | ||||
| 					} | ||||
| 					// fmt.Printf("原始文本: %s\n", initialSessage) | ||||
| 					// fmt.Printf("分割后的片段数量: %d\n", len(segments)) | ||||
| 					// for i, segment := range segments { | ||||
| 					// 	fmt.Printf("片段 %d: %s\n", i+1, segment) | ||||
| 					// } | ||||
| 					if len(segments) > 1 { | ||||
| 
 | ||||
| 						format_message := strings.Join(segments[:len(segments)-1], "") | ||||
| @ -298,52 +298,52 @@ func (s *LLMService) handleStreamingResponse(req *http.Request, data map[string] | ||||
| 				// fmt.Println("new_message", new_message) | ||||
| 
 | ||||
| 				// 最多重试一次 | ||||
| 				for i := 0; i < 1; i++ { | ||||
| 					speechResp, err := s.SynthesizeSpeech(new_message, audio_type) | ||||
| 					if err != nil { | ||||
| 						fmt.Printf("Error synthesizing speech: %v\n", err) | ||||
| 						break // 语音接口报错直接跳出 | ||||
| 					} | ||||
| 					fmt.Println("语音:", speechResp) | ||||
| 					audio = speechResp.Data.Audio | ||||
| 					if audio != "" { | ||||
| 						// Download audio from URL and trim silence | ||||
| 						resp, err := http.Get(audio) | ||||
| 						if err != nil { | ||||
| 							fmt.Printf("Error downloading audio: %v\n", err) | ||||
| 						} else { | ||||
| 							defer resp.Body.Close() | ||||
| 							audioBytes, err := io.ReadAll(resp.Body) | ||||
| 							if err != nil { | ||||
| 								fmt.Printf("Error reading audio data: %v\n", err) | ||||
| 							} else { | ||||
| 								// Save original audio first | ||||
| 								originalPath := fmt.Sprintf("audio/original_%d.wav", time.Now().UnixNano()) | ||||
| 								if err := os.WriteFile(originalPath, audioBytes, 0644); err != nil { | ||||
| 									fmt.Printf("Error saving original audio: %v\n", err) | ||||
| 								} | ||||
| 				// for i := 0; i < 1; i++ { | ||||
| 				// 	speechResp, err := s.SynthesizeSpeech(new_message, audio_type) | ||||
| 				// 	if err != nil { | ||||
| 				// 		fmt.Printf("Error synthesizing speech: %v\n", err) | ||||
| 				// 		break // 语音接口报错直接跳出 | ||||
| 				// 	} | ||||
| 				// 	fmt.Println("语音:", speechResp) | ||||
| 				// 	audio = speechResp.Data.Audio | ||||
| 				// 	if audio != "" { | ||||
| 				// 		// Download audio from URL and trim silence | ||||
| 				// 		resp, err := http.Get(audio) | ||||
| 				// 		if err != nil { | ||||
| 				// 			fmt.Printf("Error downloading audio: %v\n", err) | ||||
| 				// 		} else { | ||||
| 				// 			defer resp.Body.Close() | ||||
| 				// 			audioBytes, err := io.ReadAll(resp.Body) | ||||
| 				// 			if err != nil { | ||||
| 				// 				fmt.Printf("Error reading audio data: %v\n", err) | ||||
| 				// 			} else { | ||||
| 				// 				// Save original audio first | ||||
| 				// 				originalPath := fmt.Sprintf("audio/original_%d.wav", time.Now().UnixNano()) | ||||
| 				// 				if err := os.WriteFile(originalPath, audioBytes, 0644); err != nil { | ||||
| 				// 					fmt.Printf("Error saving original audio: %v\n", err) | ||||
| 				// 				} | ||||
| 
 | ||||
| 								// Convert audio bytes to base64 for processing | ||||
| 								audioBase64 := base64.StdEncoding.EncodeToString(audioBytes) | ||||
| 								trimmedAudio, err := s.TrimAudioSilence(audioBase64) | ||||
| 								if err != nil { | ||||
| 									fmt.Printf("Error trimming audio silence: %v\n", err) | ||||
| 								} else { | ||||
| 									// Save the trimmed audio as WAV file | ||||
| 									audio_path := fmt.Sprintf("trimmed_%d.wav", time.Now().UnixNano()) | ||||
| 									outputPath := "audio/" + audio_path | ||||
| 									if err := s.SaveBase64AsWAV(trimmedAudio, outputPath); err != nil { | ||||
| 										fmt.Printf("Error saving trimmed WAV file: %v\n", err) | ||||
| 									} | ||||
| 									audio = s.config.FILE_URL + audio_path | ||||
| 								} | ||||
| 							} | ||||
| 						} | ||||
| 						break // 获取到音频就退出 | ||||
| 					} | ||||
| 					fmt.Println("audio is empty, retry", speechResp) | ||||
| 					// time.Sleep(1 * time.Second) | ||||
| 				} | ||||
| 				// 				// Convert audio bytes to base64 for processing | ||||
| 				// 				audioBase64 := base64.StdEncoding.EncodeToString(audioBytes) | ||||
| 				// 				trimmedAudio, err := s.TrimAudioSilence(audioBase64) | ||||
| 				// 				if err != nil { | ||||
| 				// 					fmt.Printf("Error trimming audio silence: %v\n", err) | ||||
| 				// 				} else { | ||||
| 				// 					// Save the trimmed audio as WAV file | ||||
| 				// 					audio_path := fmt.Sprintf("trimmed_%d.wav", time.Now().UnixNano()) | ||||
| 				// 					outputPath := "audio/" + audio_path | ||||
| 				// 					if err := s.SaveBase64AsWAV(trimmedAudio, outputPath); err != nil { | ||||
| 				// 						fmt.Printf("Error saving trimmed WAV file: %v\n", err) | ||||
| 				// 					} | ||||
| 				// 					audio = s.config.FILE_URL + audio_path | ||||
| 				// 				} | ||||
| 				// 			} | ||||
| 				// 		} | ||||
| 				// 		break // 获取到音频就退出 | ||||
| 				// 	} | ||||
| 				// 	fmt.Println("audio is empty, retry", speechResp) | ||||
| 				// 	// time.Sleep(1 * time.Second) | ||||
| 				// } | ||||
| 
 | ||||
| 				messageChan <- Message{ | ||||
| 					Answer:         new_message, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Song367
						Song367