Text to Speech Speech to Text

speech_to_text.go 1016B

12345678910111213141516171819202122232425262728293031323334353637
  1. package handler
  2. import (
  3. "net/http"
  4. "git.links123.net/links123.com/pkg/request"
  5. "git.links123.net/Slate/CorpusAI/service"
  6. "github.com/gin-gonic/gin"
  7. )
  8. // SpeechToText godoc
  9. // @Tags 语料库
  10. // @Summary 语音转文本
  11. // @Description speech to Text
  12. // @Accept json
  13. // @Produce json
  14. // @Param file query file true "发音文件"
  15. // @Param language path string false "语言,en英文,zh中文,默认英文"
  16. // @Param rate path int false "码率,8/16 默认16"
  17. // @Success 200 {string} string "test"
  18. // @Failure 400 {string} json "{"msg": "error info"}"
  19. // @Failure 500 {string} json "{"msg": "error info"}"
  20. // @Router /en/stt [post]
  21. func SpeechToText(ctx *gin.Context){
  22. file, _, err := ctx.Request.FormFile("file")
  23. if request.Fail(ctx,http.StatusBadRequest,err){
  24. return
  25. }
  26. lang,_ := ctx.GetQuery("language")
  27. rateStr,_ := ctx.GetQuery("rate")
  28. ret, err := service.SpeechToText(file,lang,rateStr)
  29. if request.Fail(ctx,http.StatusInternalServerError,err) {
  30. return
  31. }
  32. request.Success(ctx,ret)
  33. }