删除无效输出
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 53s

This commit is contained in:
Song367 2025-06-18 18:11:25 +08:00
parent 99d6cb9f9f
commit ef15f5894e

View File

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