Browse Source

Merge branch 'feature/eta_1.6.9' into debug

hsun 1 year ago
parent
commit
d25769c9f7

+ 110 - 0
controllers/speech_recognition/speech_recognition.go

@@ -0,0 +1,110 @@
+package speech_recognition
+
+import (
+	"encoding/json"
+	"eta/eta_api/controllers"
+	"eta/eta_api/models"
+	"eta/eta_api/models/speech_recognition"
+	"eta/eta_api/services"
+	"fmt"
+	"strconv"
+	"time"
+)
+
+type SpeechRecognitionController struct {
+	controllers.BaseAuthController
+}
+
+type SpeechRecognitionCommonController struct {
+	controllers.BaseCommonController
+}
+
+// RecTaskCallback
+// @Title 语音识别回调
+// @Description 语音识别回调
+// @Param	request	body services.TencentRecTaskCallback true "type json string"
+// @Success 200 string "操作成功"
+// @router /rec_task/callback [post]
+func (this *SpeechRecognitionCommonController) RecTaskCallback() {
+	// 此接口返回指定响应体
+	br := new(services.TencentRecTaskCallbackResp)
+	defer func() {
+		_ = this.JSON(br, false, false)
+	}()
+	var req services.TencentRecTaskCallback
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Code = 403
+		br.Message = "参数解析失败"
+		return
+	}
+
+	// TODO:处理回调结果
+	apiLog := new(speech_recognition.SpeechRecognitionApiLog)
+	apiLog.RequestId = strconv.Itoa(int(req.RequestId))
+	j, _ := json.Marshal(req)
+	apiLog.RequestResult = string(j)
+	apiLog.CreateTime = time.Now().Local()
+	apiLog.ModifyTime = time.Now().Local()
+	if e := apiLog.Create(); e != nil {
+		br.Code = 403
+		br.Message = "获取回调结果失败"
+		return
+	}
+
+	br.Code = 0
+	br.Message = "success"
+}
+
+// Save
+// @Title 保存
+// @Description 保存
+// @Param	request	body speech_recognition.SpeechRecognitionSaveReq true "type json string"
+// @Success 200 string "操作成功"
+// @router /save [post]
+func (this *SpeechRecognitionCommonController) Save() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		if br.ErrMsg == "" {
+			br.IsSendEmail = false
+		}
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	//sysUser := this.SysUser
+	//if sysUser == nil {
+	//	br.Msg = "请登录"
+	//	br.ErrMsg = "请登录,SysUser Is Empty"
+	//	br.Ret = 408
+	//	return
+	//}
+	var req speech_recognition.SpeechRecognitionSaveReq
+	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
+		br.Msg = "参数有误"
+		br.ErrMsg = "参数解析失败, Err: " + e.Error()
+		return
+	}
+
+	conf, e := models.GetBusinessConf()
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取配置失败, Err: " + e.Error()
+		return
+	}
+
+	var taskReq services.TencentRecTaskReq
+	taskReq.FileUrl = req.FileName
+	taskReq.SecretId = conf[models.BusinessConfTencentApiSecretId]
+	taskReq.SecretKey = conf[models.BusinessConfTencentApiSecretKey]
+	taskReq.CallbackUrl = conf[models.BusinessConfTencentApiRecTaskCallbackUrl]
+	taskId, e := services.TencentCreateRecTask(taskReq)
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = fmt.Sprintf("TencentCreateRecTask err: %s", e.Error())
+		return
+	}
+
+	br.Data = taskId
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 2 - 1
go.mod

@@ -32,7 +32,7 @@ require (
 	github.com/shopspring/decimal v1.3.1
 	github.com/silenceper/wechat/v2 v2.1.3
 	github.com/tealeg/xlsx v1.0.5
-	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.541
+	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.873
 	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.541
 	github.com/xuri/excelize/v2 v2.7.1
 	github.com/yidane/formula v0.0.0-20210902154546-0782e1736717
@@ -101,6 +101,7 @@ require (
 	github.com/sirupsen/logrus v1.9.3 // indirect
 	github.com/spf13/cast v1.5.0 // indirect
 	github.com/stretchr/testify v1.8.1 // indirect
+	github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/asr v1.0.873 // indirect
 	github.com/tidwall/gjson v1.14.1 // indirect
 	github.com/tidwall/match v1.1.1 // indirect
 	github.com/tidwall/pretty v1.2.0 // indirect

+ 4 - 0
go.sum

@@ -428,8 +428,12 @@ github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2K
 github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
 github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
 github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/asr v1.0.873 h1:CbeN5Fdzq3xea36+ZKPQcuRwwJk0ZYQRxcyWkyK5768=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/asr v1.0.873/go.mod h1:vzSh5OxbOCyFt+SdlEd9oCQGBb1oObkD7Xfod/UPvVk=
 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.541 h1:fLtfS0fJ1RE5+b6BGVCZsqkOU8xZT1eMfRKxw2tVN9I=
 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.541/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.873 h1:VdQ+lQ98CFwbmfQj02iMVWWzdwnKubuICIa2QhzQBJI=
+github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.873/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.541 h1:whcnraDyDpbYL6YTGI5uC7p2gqu6Lo3IchZwxsRMSvY=
 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ses v1.0.541/go.mod h1:Gtw7rS9iPBdOoF5z+duWSyjSmNuRNrKKRRuG7Fblmq0=
 github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo=

+ 4 - 0
models/business_conf.go

@@ -42,6 +42,10 @@ const (
 	BusinessConfLoginEmailTemplateContent = "LoginEmailTemplateContent"
 	BusinessConfLdapBindUserSuffix        = "LdapBindUserSuffix"
 	BusinessConfLdapUserFilter            = "LdapUserFilter"
+
+	BusinessConfTencentApiSecretId           = "TencentApiSecretId"           // 腾讯云API-密钥对
+	BusinessConfTencentApiSecretKey          = "TencentApiSecretKey"          // 腾讯云API-密钥对
+	BusinessConfTencentApiRecTaskCallbackUrl = "TencentApiRecTaskCallbackUrl" // 腾讯云API-语音识别回调地址
 )
 
 const (

+ 17 - 0
models/db.go

@@ -17,6 +17,7 @@ import (
 	"eta/eta_api/models/sandbox"
 	"eta/eta_api/models/semantic_analysis"
 	"eta/eta_api/models/smart_report"
+	"eta/eta_api/models/speech_recognition"
 	"eta/eta_api/models/system"
 	"eta/eta_api/models/yb"
 	"eta/eta_api/utils"
@@ -186,6 +187,9 @@ func init() {
 	// 初始化指标刷新
 	initEdbRefresh()
 
+	// 语音识别
+	initSpeechRecognition()
+
 	// 初始化部分数据表变量(直接init会有顺序问题=_=!)
 	data_manage.InitEdbSourceVar()
 }
@@ -550,3 +554,16 @@ func initEdbRefresh() {
 		new(edb_refresh.EdbRefreshMapping),       // 指标刷新时间配置关系表
 	)
 }
+
+// initSpeechRecognition 语音识别
+func initSpeechRecognition() {
+	orm.RegisterModel(
+		new(speech_recognition.SpeechRecognition),           // 语音识别表
+		new(speech_recognition.SpeechRecognitionApiLog),     // 语音识别-API请求日志
+		new(speech_recognition.SpeechRecognitionContent),    // 语音识别-转换内容表
+		new(speech_recognition.SpeechRecognitionMenu),       // 语音识别-目录表
+		new(speech_recognition.SpeechRecognitionTag),        // 语音识别-标签表
+		new(speech_recognition.SpeechRecognitionTagMenu),    // 语音识别-标签目录表
+		new(speech_recognition.SpeechRecognitionTagMapping), // 语音识别-标签关联表
+	)
+}

+ 160 - 0
models/speech_recognition/speech_recognition.go

@@ -0,0 +1,160 @@
+package speech_recognition
+
+import (
+	"eta/eta_api/utils"
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"strings"
+	"time"
+)
+
+// SpeechRecognition 语音识别主表
+type SpeechRecognition struct {
+	SpeechRecognitionId int       `orm:"column(speech_recognition_id);pk"`
+	FileName            string    `description:"文件名称"`
+	ResourceUrl         string    `description:"文件路径"`
+	MenuId              int       `description:"目录ID"`
+	MenuPath            string    `description:"所属目录位置,例:/一级目录ID/二级目录ID"`
+	SysUserId           int       `description:"创建人ID"`
+	SysUserName         string    `description:"创建人姓名"`
+	State               int       `description:"状态:1-待转换;2-转换中;3-转换完成;4-转换失败"`
+	Abstract            string    `description:"摘要,取前几段内容"`
+	CreateTime          time.Time `description:"创建时间"`
+	ModifyTime          time.Time `description:"修改时间"`
+}
+
+var SpeechRecognitionCols = struct {
+	SpeechRecognitionId string
+	FileName            string
+	ResourceUrl         string
+	MenuId              string
+	MenuPath            string
+	SysUserId           string
+	SysUserName         string
+	State               string
+	Abstract            string
+	CreateTime          string
+	ModifyTime          string
+}{
+	SpeechRecognitionId: "speech_recognition_id",
+	FileName:            "file_name",
+	ResourceUrl:         "resource_url",
+	MenuId:              "menu_id",
+	MenuPath:            "menu_path",
+	SysUserId:           "sys_user_id",
+	SysUserName:         "sys_user_name",
+	State:               "state",
+	Abstract:            "abstract",
+	CreateTime:          "create_time",
+	ModifyTime:          "modify_time",
+}
+
+func (m *SpeechRecognition) TableName() string {
+	return "speech_recognition_id"
+}
+
+func (m *SpeechRecognition) PrimaryId() string {
+	return SpeechRecognitionCols.SpeechRecognitionId
+}
+
+func (m *SpeechRecognition) Create() (err error) {
+	o := orm.NewOrm()
+	id, err := o.Insert(m)
+	if err != nil {
+		return
+	}
+	m.SpeechRecognitionId = int(id)
+	return
+}
+
+func (m *SpeechRecognition) CreateMulti(items []*SpeechRecognition) (err error) {
+	if len(items) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
+func (m *SpeechRecognition) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}
+
+func (m *SpeechRecognition) Del() (err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	_, err = o.Raw(sql, m.SpeechRecognitionId).Exec()
+	return
+}
+
+func (m *SpeechRecognition) MultiDel(menuIds []int) (err error) {
+	if len(menuIds) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
+	_, err = o.Raw(sql, menuIds).Exec()
+	return
+}
+
+func (m *SpeechRecognition) GetItemById(id int) (item *SpeechRecognition, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	err = o.Raw(sql, id).QueryRow(&item)
+	return
+}
+
+func (m *SpeechRecognition) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognition, err error) {
+	o := orm.NewOrm()
+	order := ``
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
+	err = o.Raw(sql, pars).QueryRow(&item)
+	return
+}
+
+func (m *SpeechRecognition) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *SpeechRecognition) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognition, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+func (m *SpeechRecognition) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognition, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// SpeechRecognitionSaveReq 保存请求体
+type SpeechRecognitionSaveReq struct {
+	FileName string
+}

+ 140 - 0
models/speech_recognition/speech_recognition_api_log.go

@@ -0,0 +1,140 @@
+package speech_recognition
+
+import (
+	"eta/eta_api/utils"
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"strings"
+	"time"
+)
+
+// SpeechRecognitionApiLog 语音识别-API请求日志
+type SpeechRecognitionApiLog struct {
+	Id                  int       `orm:"column(id);pk"`
+	SpeechRecognitionId int       `description:"报告类型:1-中文研报;2-英文研报;3-智能研报"`
+	RequestId           string    `description:"API请求的唯一标识TaskId"`
+	RequestResult       string    `description:"API请求结果-JSON"`
+	CreateTime          time.Time `description:"创建时间"`
+	ModifyTime          time.Time `description:"修改时间"`
+}
+
+var SpeechRecognitionApiLogCols = struct {
+	Id                  string
+	SpeechRecognitionId string
+	RequestId           string
+	RequestResult       string
+	CreateTime          string
+	ModifyTime          string
+}{
+	Id:                  "id",
+	SpeechRecognitionId: "speech_recognition_id",
+	RequestId:           "request_id",
+	RequestResult:       "request_result",
+	CreateTime:          "create_time",
+	ModifyTime:          "modify_time",
+}
+
+func (m *SpeechRecognitionApiLog) TableName() string {
+	return "speech_recognition_api_log"
+}
+
+func (m *SpeechRecognitionApiLog) PrimaryId() string {
+	return SpeechRecognitionApiLogCols.Id
+}
+
+func (m *SpeechRecognitionApiLog) Create() (err error) {
+	o := orm.NewOrm()
+	id, err := o.Insert(m)
+	if err != nil {
+		return
+	}
+	m.Id = int(id)
+	return
+}
+
+func (m *SpeechRecognitionApiLog) CreateMulti(items []*SpeechRecognitionApiLog) (err error) {
+	if len(items) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
+func (m *SpeechRecognitionApiLog) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}
+
+func (m *SpeechRecognitionApiLog) Del() (err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	_, err = o.Raw(sql, m.Id).Exec()
+	return
+}
+
+func (m *SpeechRecognitionApiLog) MultiDel(menuIds []int) (err error) {
+	if len(menuIds) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
+	_, err = o.Raw(sql, menuIds).Exec()
+	return
+}
+
+func (m *SpeechRecognitionApiLog) GetItemById(id int) (item *SpeechRecognitionApiLog, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	err = o.Raw(sql, id).QueryRow(&item)
+	return
+}
+
+func (m *SpeechRecognitionApiLog) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SpeechRecognitionApiLog, err error) {
+	o := orm.NewOrm()
+	order := ``
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
+	err = o.Raw(sql, pars).QueryRow(&item)
+	return
+}
+
+func (m *SpeechRecognitionApiLog) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *SpeechRecognitionApiLog) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SpeechRecognitionApiLog, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+func (m *SpeechRecognitionApiLog) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SpeechRecognitionApiLog, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 4 - 0
models/speech_recognition/speech_recognition_content.go

@@ -0,0 +1,4 @@
+package speech_recognition
+
+type SpeechRecognitionContent struct {
+}

+ 4 - 0
models/speech_recognition/speech_recognition_menu.go

@@ -0,0 +1,4 @@
+package speech_recognition
+
+type SpeechRecognitionMenu struct {
+}

+ 4 - 0
models/speech_recognition/speech_recognition_tag.go

@@ -0,0 +1,4 @@
+package speech_recognition
+
+type SpeechRecognitionTag struct {
+}

+ 4 - 0
models/speech_recognition/speech_recognition_tag_mapping.go

@@ -0,0 +1,4 @@
+package speech_recognition
+
+type SpeechRecognitionTagMapping struct {
+}

+ 4 - 0
models/speech_recognition/speech_recognition_tag_menu.go

@@ -0,0 +1,4 @@
+package speech_recognition
+
+type SpeechRecognitionTagMenu struct {
+}

+ 18 - 0
routers/commentsRouter.go

@@ -6055,6 +6055,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/speech_recognition:SpeechRecognitionCommonController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/speech_recognition:SpeechRecognitionCommonController"],
+        beego.ControllerComments{
+            Method: "RecTaskCallback",
+            Router: `/rec_task/callback`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/speech_recognition:SpeechRecognitionCommonController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/speech_recognition:SpeechRecognitionCommonController"],
+        beego.ControllerComments{
+            Method: "Save",
+            Router: `/save`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/trade_analysis:TradeAnalysisController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/trade_analysis:TradeAnalysisController"],
         beego.ControllerComments{
             Method: "GetClassifyName",

+ 7 - 0
routers/router.go

@@ -27,6 +27,7 @@ import (
 	"eta/eta_api/controllers/sandbox"
 	"eta/eta_api/controllers/semantic_analysis"
 	"eta/eta_api/controllers/smart_report"
+	"eta/eta_api/controllers/speech_recognition"
 	"eta/eta_api/controllers/trade_analysis"
 	"github.com/beego/beego/v2/server/web"
 	"github.com/beego/beego/v2/server/web/filter/cors"
@@ -356,6 +357,12 @@ func init() {
 				&controllers.ChartPermissionController{},
 			),
 		),
+		web.NSNamespace("/speech_recognition",
+			web.NSInclude(
+				&speech_recognition.SpeechRecognitionCommonController{},
+				&speech_recognition.SpeechRecognitionController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 1 - 0
services/speech_recognition.go

@@ -0,0 +1 @@
+package services

+ 83 - 0
services/tecent_asr.go

@@ -0,0 +1,83 @@
+package services
+
+import (
+	"fmt"
+
+	asr "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/asr/v20190614"
+	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
+	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
+	"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
+)
+
+type TencentRecTaskReq struct {
+	SecretId    string
+	SecretKey   string
+	FileUrl     string
+	CallbackUrl string
+}
+
+// TencentCreateRecTask 创建录音文件识别
+func TencentCreateRecTask(req TencentRecTaskReq) (taskId int, err error) {
+	if req.SecretId == "" || req.SecretKey == "" || req.FileUrl == "" {
+		err = fmt.Errorf("参数有误, SecretId: %s, SecretKey: %s, FileUrl: %s", req.SecretId, req.SecretKey, req.FileUrl)
+		return
+	}
+	credential := common.NewCredential(
+		req.SecretId,
+		req.SecretKey,
+	)
+	cpf := profile.NewClientProfile()
+	cpf.HttpProfile.Endpoint = "asr.tencentcloudapi.com"
+	client, e := asr.NewClient(credential, "", cpf)
+	if e != nil {
+		err = fmt.Errorf("asr NewClient err: %s", e.Error())
+		return
+	}
+
+	// 实例化一个请求对象, 具体参数看文档https://cloud.tencent.com/document/product/1093/37823
+	request := asr.NewCreateRecTaskRequest()
+	request.EngineModelType = common.StringPtr("16k_zh")
+	request.ChannelNum = common.Uint64Ptr(2)
+	request.ResTextFormat = common.Uint64Ptr(2)
+	request.SourceType = common.Uint64Ptr(0)
+	request.Url = common.StringPtr(req.FileUrl)
+	if req.CallbackUrl != "" {
+		request.CallbackUrl = common.StringPtr(req.CallbackUrl)
+	}
+	request.SpeakerDiarization = common.Int64Ptr(1)
+	request.SpeakerNumber = common.Int64Ptr(0)
+	request.ConvertNumMode = common.Int64Ptr(0)
+	request.FilterDirty = common.Int64Ptr(2)
+	request.FilterPunc = common.Int64Ptr(0)
+	request.FilterModal = common.Int64Ptr(2)
+
+	// 返回的resp是一个CreateRecTaskResponse的实例
+	response, e := client.CreateRecTask(request)
+	if _, ok := e.(*errors.TencentCloudSDKError); ok {
+		err = fmt.Errorf("asr CreateRecTask err: %s", e.Error())
+		return
+	}
+	// 唯一标识, 回调会用到
+	taskId = int(*response.Response.Data.TaskId)
+	//fmt.Printf("%s", response.ToJsonString())
+	return
+}
+
+// TencentRecTaskCallback 录音识别回调参数
+type TencentRecTaskCallback struct {
+	Code         int     `description:"任务状态码,0为成功,其他:失败;详见https://cloud.tencent.com/document/product/1093/52632"`
+	Message      string  `description:"失败原因文字描述,成功时此值为空"`
+	RequestId    uint64  `json:"requestId" description:"任务唯一标识,与录音识别请求中返回的TaskId一致。数据格式必须设置为Uint64"`
+	Appid        uint64  `description:"腾讯云应用ID"`
+	ProjectId    int     `json:"projectid" description:"腾讯云项目ID"`
+	AudioUrl     string  `json:"audioUrl" description:"语音URL,如创建任务时为上传数据的方式,则不包含该字段"`
+	Text         string  `description:"识别出的结果文本"`
+	ResultDetail string  `json:"resultDetail" description:"包含详细识别结果,如创建任务时 ResTextFormat 为0,则不包含该字段"`
+	AudioTime    float64 `json:"audioTime" description:"语音总时长"`
+}
+
+// TencentRecTaskCallbackResp 录音识别回调响应体
+type TencentRecTaskCallbackResp struct {
+	Code    int    `description:"0为成功, 其他值代表失败"`
+	Message string `description:"失败原因说明"`
+}