Text to Speech Speech to Text

index.go 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package handler
  2. import (
  3. "git.links123.net/links123.com/pkg/request"
  4. "git.links123.net/Slate/CorpusAI/service"
  5. "git.links123.net/Slate/CorpusAI/service/api"
  6. "github.com/Unknwon/i18n"
  7. "github.com/gin-gonic/gin"
  8. "errors"
  9. "git.links123.net/Slate/CorpusAI/config"
  10. )
  11. func Healthy(ctx *gin.Context) {
  12. cp := &api.CommonParams{}
  13. if request.ParseParamFail(ctx, cp) {
  14. return
  15. }
  16. request.Success(ctx, gin.H{"msg": i18n.Tr(cp.TargetStr, "hi", "Paul")})
  17. }
  18. // TextToSpeech godoc
  19. // @Tags 语料库
  20. // @Summary 获取音频接口base url
  21. // @Description 获取音频接口base url(主要用于海内外接口地址分开)
  22. // @Accept json
  23. // @Produce json
  24. // @Param ip query string false "IP地址, 默认无需传, 自动获取"
  25. // @Success 200 {string} json "{"audio_base_url": "https://campusai.links123.com/v1/en/tts","country_code": "国家code","ip": "ip地址"}"
  26. // @Failure 400 {string} json "{"msg": "error info"}"
  27. // @Failure 500 {string} json "{"msg": "error info"}"
  28. // @Router /en/audio_base_url [get]
  29. func GetAudioBaseUrl(ctx *gin.Context) {
  30. ip := ctx.DefaultQuery("ip", ctx.ClientIP())
  31. if ip == "" {
  32. request.Fail(ctx, 400, errors.New("client ip error"))
  33. return
  34. }
  35. countryCode := service.Ip2Country(ip)
  36. appConfig := config.C.App
  37. baseUrl := appConfig.CNHost + "/v1/en/tts"
  38. if countryCode!="" && countryCode != "CN" {
  39. baseUrl = appConfig.HKHost + "/v1/en/tts"
  40. }
  41. request.Success(ctx, gin.H{"audio_base_url": baseUrl,"country_code":countryCode,"ip":ip})
  42. }