feat: 长文本语音合成
This commit is contained in:
@@ -91,6 +91,22 @@ func (s *InteractionService) ToggleLike(userId, programId string) (bool, error)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// GetLikeList 获取点赞列表
|
||||
func (s *InteractionService) GetLikeList(userId string, req radioReq.GetLikeList) ([]radio.RadioLike, int64, error) {
|
||||
db := global.DB.Model(&radio.RadioLike{}).Where("user_id = ?", userId).Preload("RadioProgram")
|
||||
var list []radio.RadioLike
|
||||
var total int64
|
||||
|
||||
err := db.Count(&total).Error
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
offset := (req.Current - 1) * req.PageSize
|
||||
err = db.Offset(offset).Limit(req.PageSize).Order("created_at DESC").Find(&list).Error
|
||||
return list, total, err
|
||||
}
|
||||
|
||||
// IsLiked 检查是否已点赞
|
||||
func (s *InteractionService) IsLiked(userId, programId string) (bool, error) {
|
||||
var count int64
|
||||
@@ -124,7 +140,7 @@ func (s *InteractionService) RemoveFavorite(userId, programId string) error {
|
||||
|
||||
// GetFavoriteList 获取收藏列表
|
||||
func (s *InteractionService) GetFavoriteList(userId string, info radioReq.GetFavoriteList) ([]radio.RadioFavorite, int64, error) {
|
||||
db := global.DB.Model(&radio.RadioFavorite{}).Where("user_id = ?", userId)
|
||||
db := global.DB.Model(&radio.RadioFavorite{}).Where("user_id = ?", userId).Preload("RadioProgram")
|
||||
var list []radio.RadioFavorite
|
||||
var total int64
|
||||
|
||||
@@ -188,3 +204,7 @@ func (s *InteractionService) DeleteAllHistory(userId string) error {
|
||||
func (s *InteractionService) RemoveAllFavorite(userId string) error {
|
||||
return global.DB.Where("user_id = ?", userId).Delete(&radio.RadioFavorite{}).Error
|
||||
}
|
||||
|
||||
func (s *InteractionService) RemoveAllLike(userId string) error {
|
||||
return global.DB.Where("user_id = ?", userId).Delete(&radio.RadioLike{}).Error
|
||||
}
|
||||
|
||||
@@ -127,8 +127,9 @@ func (s *ProgramService) GenerateTTS(programId string) error {
|
||||
|
||||
// 2. 调用TTS提交任务 (异步,后台处理)
|
||||
ttsReq := TTSTextToSpeechRequest{
|
||||
Text: program.Content,
|
||||
VoiceType: 101021, // 亲和女声
|
||||
Text: program.Content,
|
||||
//VoiceType: 101001, // 智瑜 情感女声
|
||||
VoiceType: 101013, // 智辉 新闻男声
|
||||
Speed: 0, // 正常语速
|
||||
Volume: 0, // 正常音量
|
||||
ProgramId: programId,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"sundynix-go/global"
|
||||
@@ -160,7 +161,7 @@ func (t *TTSService) doSubmitTTSTask(req TTSTextToSpeechRequest) (string, error)
|
||||
// waitForResult 轮询查询任务结果,返回音频下载URL
|
||||
func (t *TTSService) waitForResult(taskId string) (string, error) {
|
||||
maxRetries := 30
|
||||
interval := 5 * time.Second
|
||||
interval := 15 * time.Second
|
||||
|
||||
for i := 0; i < maxRetries; i++ {
|
||||
time.Sleep(interval)
|
||||
@@ -256,8 +257,9 @@ func (t *TTSService) uploadToOSS(audioData []byte, programId string) (string, er
|
||||
if !ok {
|
||||
return "", fmt.Errorf("获取MinIO客户端失败")
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("audio/%s/%s.mp3", time.Now().Format("2006-01-02"), programId)
|
||||
timestamp := time.Now().UnixMicro()
|
||||
timestr := strconv.FormatInt(timestamp, 10)
|
||||
key := fmt.Sprintf("audio/%s/%s.mp3", time.Now().Format("2006-01-02"), programId+"-"+timestr)
|
||||
filename := fmt.Sprintf("program-%s.mp3", programId)
|
||||
|
||||
fileURL, err := minioClient.UploadBytes(audioData, key, "audio/mpeg")
|
||||
|
||||
Reference in New Issue
Block a user