| | |
| | | "speechAnalysis/constvar" |
| | | "speechAnalysis/models" |
| | | "speechAnalysis/pkg/logx" |
| | | "strings" |
| | | ) |
| | | |
| | | // Response 结构体用于存储响应体的内容 |
| | |
| | | return |
| | | } |
| | | logx.Infof("AnalysisAudio result: %v", resp) |
| | | words := GetWordFromText(resp.Result, audio) |
| | | |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{ |
| | | err = models.NewAudioSearch().SetOrm(db).SetID(audioId).UpdateByMap(map[string]interface{}{ |
| | | "audio_status": constvar.AudioStatusFinish, |
| | | "score": resp.Score, |
| | | "tags": strings.Join(words, ","), |
| | | }) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | err = models.NewAudioTextSearch().Save(&models.AudioText{ |
| | | err = models.NewAudioTextSearch().SetOrm(db).Save(&models.AudioText{ |
| | | AudioID: audio.ID, |
| | | AudioText: resp.Result, |
| | | }) |
| | |
| | | }) |
| | | if err != nil { |
| | | logx.Infof("AnalysisAudio success but update record failed: %v", err) |
| | | _ = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{"audio_status": constvar.AudioStatusFailed}) |
| | | return |
| | | } |
| | | }() |
| | | |
| | | return nil |
| | | } |
| | | |
| | | func GetWordFromText(text string, audio *models.Audio) (words []string) { |
| | | if audio == nil { |
| | | return nil |
| | | } |
| | | wordRecords, err := models.NewWordSearch().SetLocomotiveNumber(audio.LocomotiveNumber).FindNotTotal() |
| | | if err != nil || len(wordRecords) == 0 { |
| | | return nil |
| | | } |
| | | for _, v := range wordRecords { |
| | | if strings.Contains(text, v.Content) { |
| | | words = append(words, v.Content) |
| | | } |
| | | } |
| | | return words |
| | | } |