speech_recognition.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. package speech_recognition
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/controllers"
  5. "eta/eta_api/models"
  6. "eta/eta_api/models/speech_recognition"
  7. "eta/eta_api/services"
  8. "eta/eta_api/services/alarm_msg"
  9. "eta/eta_api/utils"
  10. "fmt"
  11. "strings"
  12. "time"
  13. )
  14. type SpeechRecognitionController struct {
  15. controllers.BaseAuthController
  16. }
  17. type SpeechRecognitionCommonController struct {
  18. controllers.BaseCommonController
  19. }
  20. // RecTaskCallback
  21. // @Title 语音识别回调
  22. // @Description 语音识别回调
  23. // @Param request body services.TencentRecTaskCallback true "type json string"
  24. // @Success 200 string "操作成功"
  25. // @router /rec_task/callback [post]
  26. func (this *SpeechRecognitionCommonController) RecTaskCallback() {
  27. // 此接口返回指定响应体
  28. br := new(services.TencentRecTaskCallbackResp)
  29. var errMsg string
  30. defer func() {
  31. if errMsg != "" {
  32. br.Code = 403
  33. br.Message = "回调失败"
  34. go alarm_msg.SendAlarmMsg(fmt.Sprintf("语音识别回调失败, ErrMsg: %s", errMsg), 1)
  35. } else {
  36. br.Code = 0
  37. br.Message = "success"
  38. }
  39. _ = this.JSON(br, false, false)
  40. }()
  41. code, _ := this.GetInt("code", -1)
  42. requestId, _ := this.GetInt("requestId", 0)
  43. detail := this.GetString("resultDetail")
  44. utils.FileLog.Info(fmt.Sprintf("RecTaskCallback, requestId: %d", requestId))
  45. // 获取taskId对应的API请求及语音识别
  46. logOb := new(speech_recognition.SpeechRecognitionApiLog)
  47. cond := fmt.Sprintf(` AND %s = ?`, speech_recognition.SpeechRecognitionApiLogCols.RequestId)
  48. pars := make([]interface{}, 0)
  49. pars = append(pars, requestId)
  50. apiLog, e := logOb.GetItemByCondition(cond, pars, "")
  51. if e != nil {
  52. errMsg = "获取API记录失败"
  53. utils.FileLog.Info("API回调-获取请求记录失败, Err: " + e.Error())
  54. return
  55. }
  56. speechOb := new(speech_recognition.SpeechRecognition)
  57. speechItem, e := speechOb.GetItemById(apiLog.SpeechRecognitionId)
  58. if e != nil {
  59. errMsg = "获取语音识别失败"
  60. utils.FileLog.Info("获取语音识别失败, Err: " + e.Error())
  61. return
  62. }
  63. // API结果返回有误
  64. nowTime := time.Now().Local()
  65. if code != speech_recognition.ApiRequestCodeSuccess {
  66. convertRemark := speech_recognition.ApiErrMsgMapping[code]
  67. if convertRemark == "" {
  68. convertRemark = fmt.Sprintf("未知错误: %d", code)
  69. }
  70. speechItem.ConvertRemark = convertRemark
  71. speechItem.State = speech_recognition.SpeechRecognitionStateFail
  72. speechItem.ModifyTime = nowTime
  73. speechCols := []string{speech_recognition.SpeechRecognitionCols.ConvertRemark, speech_recognition.SpeechRecognitionCols.State, speech_recognition.SpeechRecognitionCols.ModifyTime}
  74. apiLog.RequestCode = code
  75. apiLog.RequestResult = convertRemark
  76. apiLog.ModifyTime = nowTime
  77. apiLogCols := []string{speech_recognition.SpeechRecognitionApiLogCols.RequestCode, speech_recognition.SpeechRecognitionApiLogCols.RequestResult, speech_recognition.SpeechRecognitionApiLogCols.ModifyTime}
  78. // 更新语音识别及API记录
  79. if e := speech_recognition.UpdateSpeechAndApiLog(speechItem, speechCols, apiLog, apiLogCols); e != nil {
  80. errMsg = "更新API返回结果失败"
  81. utils.FileLog.Info("更新API返回结果失败, Err: " + e.Error())
  82. }
  83. return
  84. }
  85. // 解析转写段落内容
  86. sentences := make([]*services.TencentRecTaskSentenceDetail, 0)
  87. if e := json.Unmarshal([]byte(detail), &sentences); e != nil {
  88. errMsg = "解析语音识别内容失败"
  89. utils.FileLog.Info("解析语音识别内容失败, Err: " + e.Error())
  90. return
  91. }
  92. contents := make([]*speech_recognition.SpeechRecognitionContent, 0)
  93. sorts := 0 // API返回的结果本身是已排过序的
  94. for _, v := range sentences {
  95. sorts += 1
  96. t := new(speech_recognition.SpeechRecognitionContent)
  97. t.SpeechRecognitionId = speechItem.SpeechRecognitionId
  98. t.Sort = sorts
  99. t.Content = v.FinalSentence
  100. t.StartMs = v.StartMs
  101. t.EndMs = v.EndMs
  102. t.CreateTime = nowTime
  103. t.ModifyTime = nowTime
  104. contents = append(contents, t)
  105. }
  106. speechItem.State = speech_recognition.SpeechRecognitionStateSuccess
  107. speechItem.ModifyTime = nowTime
  108. speechCols := []string{speech_recognition.SpeechRecognitionCols.State, speech_recognition.SpeechRecognitionCols.ModifyTime}
  109. apiLog.RequestCode = code
  110. apiLog.RequestResult = detail
  111. apiLog.ModifyTime = time.Now().Local()
  112. apiLogCols := []string{speech_recognition.SpeechRecognitionApiLogCols.RequestCode, speech_recognition.SpeechRecognitionApiLogCols.RequestResult, speech_recognition.SpeechRecognitionApiLogCols.ModifyTime}
  113. // 新增解析内容并更新语音识别及API记录
  114. if e := speech_recognition.CreateContentAndUpdateSpeechAndApiLog(contents, speechItem, speechCols, apiLog, apiLogCols); e != nil {
  115. errMsg = "新增API返回结果失败"
  116. utils.FileLog.Info("新增API返回结果失败, Err: " + e.Error())
  117. }
  118. }
  119. // Convert
  120. // @Title 语音转换
  121. // @Description 语音转换
  122. // @Param request body speech_recognition.SpeechRecognitionConvertReq true "type json string"
  123. // @Success 200 string "操作成功"
  124. // @router /convert [post]
  125. func (this *SpeechRecognitionController) Convert() {
  126. br := new(models.BaseResponse).Init()
  127. defer func() {
  128. if br.ErrMsg == "" {
  129. br.IsSendEmail = false
  130. }
  131. this.Data["json"] = br
  132. this.ServeJSON()
  133. }()
  134. sysUser := this.SysUser
  135. if sysUser == nil {
  136. br.Msg = "请登录"
  137. br.ErrMsg = "请登录,SysUser Is Empty"
  138. br.Ret = 408
  139. return
  140. }
  141. var req speech_recognition.SpeechRecognitionConvertReq
  142. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  143. br.Msg = "参数有误"
  144. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  145. return
  146. }
  147. if req.MenuId <= 0 {
  148. br.Msg = "请选择目录"
  149. return
  150. }
  151. if len(req.Files) == 0 {
  152. br.Msg = "请上传转写文件"
  153. return
  154. }
  155. for _, r := range req.Files {
  156. if r.FileName == "" && r.ResourceUrl == "" {
  157. br.Msg = "转写文件有误,请检查"
  158. return
  159. }
  160. }
  161. speeches := make([]*speech_recognition.SpeechRecognition, 0)
  162. nowTime := time.Now().Local()
  163. for _, v := range req.Files {
  164. t := new(speech_recognition.SpeechRecognition)
  165. t.FileName = v.FileName
  166. t.ResourceUrl = v.ResourceUrl
  167. t.MenuId = req.MenuId
  168. // TODO:所属目录位置
  169. t.SysUserId = sysUser.AdminId
  170. t.SysUserName = sysUser.RealName
  171. t.State = speech_recognition.SpeechRecognitionStateWait
  172. t.CreateTime = nowTime
  173. t.ModifyTime = nowTime
  174. // CreateMulti拿不到主键, 此处用循环新增获取
  175. if e := t.Create(); e != nil {
  176. br.Msg = "操作失败"
  177. br.ErrMsg = "批量新增转写文件失败, Err: " + e.Error()
  178. return
  179. }
  180. speeches = append(speeches, t)
  181. }
  182. // 批量转写语音
  183. go func() {
  184. services.BatchConvertSpeech(speeches)
  185. }()
  186. br.Ret = 200
  187. br.Success = true
  188. br.Msg = "操作成功"
  189. }
  190. // ConvertList
  191. // @Title 转换列表
  192. // @Description 转换列表
  193. // @Success 200 {object} speech_recognition.SpeechRecognitionItem
  194. // @router /convert_list [get]
  195. func (this *SpeechRecognitionController) ConvertList() {
  196. br := new(models.BaseResponse).Init()
  197. defer func() {
  198. if br.ErrMsg == "" {
  199. br.IsSendEmail = false
  200. }
  201. this.Data["json"] = br
  202. this.ServeJSON()
  203. }()
  204. sysUser := this.SysUser
  205. if sysUser == nil {
  206. br.Msg = "请登录"
  207. br.ErrMsg = "请登录,SysUser Is Empty"
  208. br.Ret = 408
  209. return
  210. }
  211. // 仅取待转换和转换失败的
  212. states := []int{speech_recognition.SpeechRecognitionStateWait, speech_recognition.SpeechRecognitionStateFail}
  213. speechOb := new(speech_recognition.SpeechRecognition)
  214. cond := fmt.Sprintf(` %s = ? AND %s IN (%s)`, speech_recognition.SpeechRecognitionCols.SysUserId, speech_recognition.SpeechRecognitionCols.State, utils.GetOrmInReplace(len(states)))
  215. pars := make([]interface{}, 0)
  216. pars = append(pars, sysUser.AdminId, states)
  217. list, e := speechOb.GetItemsByCondition(cond, pars, []string{}, "")
  218. if e != nil {
  219. br.Msg = "获取失败"
  220. br.ErrMsg = "获取转写文件列表失败, Err: " + e.Error()
  221. return
  222. }
  223. resp := make([]*speech_recognition.SpeechRecognitionItem, 0)
  224. for _, v := range list {
  225. resp = append(resp, speech_recognition.FormatSpeechRecognition2Item(v))
  226. }
  227. br.Data = resp
  228. br.Ret = 200
  229. br.Success = true
  230. br.Msg = "获取成功"
  231. }
  232. // TODO:Save
  233. // @Title 保存内容
  234. // @Description 保存内容
  235. // @Param request body speech_recognition.SpeechRecognitionSaveReq true "type json string"
  236. // @Success 200 string "操作成功"
  237. // @router /save [post]
  238. func (this *SpeechRecognitionController) Save() {
  239. br := new(models.BaseResponse).Init()
  240. defer func() {
  241. if br.ErrMsg == "" {
  242. br.IsSendEmail = false
  243. }
  244. this.Data["json"] = br
  245. this.ServeJSON()
  246. }()
  247. sysUser := this.SysUser
  248. if sysUser == nil {
  249. br.Msg = "请登录"
  250. br.ErrMsg = "请登录,SysUser Is Empty"
  251. br.Ret = 408
  252. return
  253. }
  254. var req speech_recognition.SpeechRecognitionSaveReq
  255. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  256. br.Msg = "参数有误"
  257. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  258. return
  259. }
  260. br.Ret = 200
  261. br.Success = true
  262. br.Msg = "操作成功"
  263. }
  264. // RemoveFile
  265. // @Title (软)删除文件
  266. // @Description (软)删除文件
  267. // @Param request body speech_recognition.SpeechRecognitionRemoveFileReq true "type json string"
  268. // @Success 200 string "操作成功"
  269. // @router /remove_file [post]
  270. func (this *SpeechRecognitionController) RemoveFile() {
  271. br := new(models.BaseResponse).Init()
  272. defer func() {
  273. if br.ErrMsg == "" {
  274. br.IsSendEmail = false
  275. }
  276. this.Data["json"] = br
  277. this.ServeJSON()
  278. }()
  279. sysUser := this.SysUser
  280. if sysUser == nil {
  281. br.Msg = "请登录"
  282. br.ErrMsg = "请登录,SysUser Is Empty"
  283. br.Ret = 408
  284. return
  285. }
  286. var req speech_recognition.SpeechRecognitionRemoveFileReq
  287. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  288. br.Msg = "参数有误"
  289. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  290. return
  291. }
  292. if req.SpeechRecognitionId <= 0 {
  293. br.Msg = "参数有误"
  294. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  295. return
  296. }
  297. speechOb := new(speech_recognition.SpeechRecognition)
  298. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  299. if e != nil {
  300. if e.Error() == utils.ErrNoRow() {
  301. br.Msg = "转写文件不存在,请刷新页面"
  302. return
  303. }
  304. br.Msg = "操作失败"
  305. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  306. return
  307. }
  308. speechItem.FileState = speech_recognition.SpeechRecognitionFileRemoveFlag
  309. speechItem.ModifyTime = time.Now().Local()
  310. updateCols := []string{speech_recognition.SpeechRecognitionCols.FileState, speech_recognition.SpeechRecognitionCols.ModifyTime}
  311. if e = speechItem.Update(updateCols); e != nil {
  312. br.Msg = "操作失败"
  313. br.ErrMsg = "软删除转写文件失败, Err: " + e.Error()
  314. return
  315. }
  316. br.Ret = 200
  317. br.Success = true
  318. br.Msg = "操作成功"
  319. }
  320. // Rename
  321. // @Title 重命名
  322. // @Description 重命名
  323. // @Param request body speech_recognition.SpeechRecognitionRenameReq true "type json string"
  324. // @Success 200 string "操作成功"
  325. // @router /rename [post]
  326. func (this *SpeechRecognitionController) Rename() {
  327. br := new(models.BaseResponse).Init()
  328. defer func() {
  329. if br.ErrMsg == "" {
  330. br.IsSendEmail = false
  331. }
  332. this.Data["json"] = br
  333. this.ServeJSON()
  334. }()
  335. sysUser := this.SysUser
  336. if sysUser == nil {
  337. br.Msg = "请登录"
  338. br.ErrMsg = "请登录,SysUser Is Empty"
  339. br.Ret = 408
  340. return
  341. }
  342. var req speech_recognition.SpeechRecognitionRenameReq
  343. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  344. br.Msg = "参数有误"
  345. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  346. return
  347. }
  348. if req.SpeechRecognitionId <= 0 {
  349. br.Msg = "参数有误"
  350. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  351. return
  352. }
  353. req.FileName = strings.TrimSpace(req.FileName)
  354. if req.FileName == "" {
  355. br.Msg = "请输入文件名称"
  356. return
  357. }
  358. speechOb := new(speech_recognition.SpeechRecognition)
  359. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  360. if e != nil {
  361. if e.Error() == utils.ErrNoRow() {
  362. br.Msg = "转写文件不存在,请刷新页面"
  363. return
  364. }
  365. br.Msg = "操作失败"
  366. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  367. return
  368. }
  369. // 重名校验
  370. {
  371. cond := fmt.Sprintf(` %s = ? AND %s <> ?`, speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.SpeechRecognitionId)
  372. pars := make([]interface{}, 0)
  373. pars = append(pars, req.FileName, req.SpeechRecognitionId)
  374. exists, e := speechOb.GetItemByCondition(cond, pars, "")
  375. if e != nil && e.Error() != utils.ErrNoRow() {
  376. br.Msg = "操作失败"
  377. br.ErrMsg = "获取同名转写文件失败, Err: " + e.Error()
  378. return
  379. }
  380. if exists != nil && exists.SpeechRecognitionId > 0 {
  381. br.Msg = "分类名称已存在,请重新输入"
  382. return
  383. }
  384. }
  385. speechItem.FileName = req.FileName
  386. speechItem.ModifyTime = time.Now().Local()
  387. updateCols := []string{speech_recognition.SpeechRecognitionCols.FileName, speech_recognition.SpeechRecognitionCols.ModifyTime}
  388. if e = speechItem.Update(updateCols); e != nil {
  389. br.Msg = "操作失败"
  390. br.ErrMsg = "转写文件重命名失败, Err: " + e.Error()
  391. return
  392. }
  393. br.Ret = 200
  394. br.Success = true
  395. br.Msg = "操作成功"
  396. }
  397. // Remove
  398. // @Title 删除
  399. // @Description 删除
  400. // @Param request body speech_recognition.SpeechRecognitionRemoveReq true "type json string"
  401. // @Success 200 string "操作成功"
  402. // @router /remove [post]
  403. func (this *SpeechRecognitionController) Remove() {
  404. br := new(models.BaseResponse).Init()
  405. defer func() {
  406. if br.ErrMsg == "" {
  407. br.IsSendEmail = false
  408. }
  409. this.Data["json"] = br
  410. this.ServeJSON()
  411. }()
  412. sysUser := this.SysUser
  413. if sysUser == nil {
  414. br.Msg = "请登录"
  415. br.ErrMsg = "请登录,SysUser Is Empty"
  416. br.Ret = 408
  417. return
  418. }
  419. var req speech_recognition.SpeechRecognitionRemoveReq
  420. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  421. br.Msg = "参数有误"
  422. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  423. return
  424. }
  425. if req.SpeechRecognitionId <= 0 {
  426. br.Msg = "参数有误"
  427. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  428. return
  429. }
  430. speechOb := new(speech_recognition.SpeechRecognition)
  431. speechItem, e := speechOb.GetItemById(req.SpeechRecognitionId)
  432. if e != nil {
  433. if e.Error() == utils.ErrNoRow() {
  434. br.Ret = 200
  435. br.Success = true
  436. br.Msg = "操作成功"
  437. return
  438. }
  439. br.Msg = "操作失败"
  440. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  441. return
  442. }
  443. if e = speechItem.Del(); e != nil {
  444. br.Msg = "操作失败"
  445. br.ErrMsg = "删除转写文件失败, Err: " + e.Error()
  446. return
  447. }
  448. // 清除标签关联
  449. go func() {
  450. mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
  451. _ = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId)
  452. }()
  453. br.Ret = 200
  454. br.Success = true
  455. br.Msg = "操作成功"
  456. }
  457. // SaveTag
  458. // @Title 保存标签
  459. // @Description 保存标签
  460. // @Param request body speech_recognition.SpeechRecognitionSaveTagReq true "type json string"
  461. // @Success 200 string "操作成功"
  462. // @router /save_tag [post]
  463. func (this *SpeechRecognitionController) SaveTag() {
  464. br := new(models.BaseResponse).Init()
  465. defer func() {
  466. if br.ErrMsg == "" {
  467. br.IsSendEmail = false
  468. }
  469. this.Data["json"] = br
  470. this.ServeJSON()
  471. }()
  472. sysUser := this.SysUser
  473. if sysUser == nil {
  474. br.Msg = "请登录"
  475. br.ErrMsg = "请登录,SysUser Is Empty"
  476. br.Ret = 408
  477. return
  478. }
  479. var req speech_recognition.SpeechRecognitionSaveTagReq
  480. if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  481. br.Msg = "参数有误"
  482. br.ErrMsg = "参数解析失败, Err: " + e.Error()
  483. return
  484. }
  485. if req.SpeechRecognitionId <= 0 {
  486. br.Msg = "参数有误"
  487. br.ErrMsg = fmt.Sprintf("参数有误, SpeechRecognitionId: %d", req.SpeechRecognitionId)
  488. return
  489. }
  490. speechOb := new(speech_recognition.SpeechRecognition)
  491. _, e := speechOb.GetItemById(req.SpeechRecognitionId)
  492. if e != nil {
  493. if e.Error() == utils.ErrNoRow() {
  494. br.Msg = "转写文件不存在,请刷新页面"
  495. return
  496. }
  497. br.Msg = "操作失败"
  498. br.ErrMsg = "获取转写文件失败, Err: " + e.Error()
  499. return
  500. }
  501. // 清除原标签
  502. mappingOb := new(speech_recognition.SpeechRecognitionTagMapping)
  503. if e = mappingOb.ClearMappingBySpeechId(req.SpeechRecognitionId); e != nil {
  504. br.Msg = "操作失败"
  505. br.ErrMsg = "清除转写文件标签失败, Err: " + e.Error()
  506. return
  507. }
  508. // 保存新标签
  509. if len(req.TagIds) > 0 {
  510. mappings := make([]*speech_recognition.SpeechRecognitionTagMapping, 0)
  511. for _, v := range req.TagIds {
  512. if v <= 0 {
  513. continue
  514. }
  515. mappings = append(mappings, &speech_recognition.SpeechRecognitionTagMapping{
  516. TagId: v,
  517. SpeechRecognitionId: req.SpeechRecognitionId,
  518. })
  519. }
  520. if e = mappingOb.CreateMulti(mappings); e != nil {
  521. br.Msg = "操作失败"
  522. br.ErrMsg = "批量新增转写文件标签失败, Err: " + e.Error()
  523. return
  524. }
  525. }
  526. br.Ret = 200
  527. br.Success = true
  528. br.Msg = "操作成功"
  529. }
  530. // TODO:List
  531. // @Title 语音识别列表
  532. // @Description 语音识别列表
  533. // @Param ParentId query int false "父级ID"
  534. // @Success 200 {object} speech_recognition.SpeechRecognitionMenuNodeItem
  535. // @router /list [get]
  536. func (this *SpeechRecognitionController) List() {
  537. br := new(models.BaseResponse).Init()
  538. defer func() {
  539. if br.ErrMsg == "" {
  540. br.IsSendEmail = false
  541. }
  542. this.Data["json"] = br
  543. this.ServeJSON()
  544. }()
  545. sysUser := this.SysUser
  546. if sysUser == nil {
  547. br.Msg = "请登录"
  548. br.ErrMsg = "请登录,SysUser Is Empty"
  549. br.Ret = 408
  550. return
  551. }
  552. // TODO:标签列表
  553. br.Ret = 200
  554. br.Success = true
  555. br.Msg = "获取成功"
  556. }
  557. // TODO:Detail
  558. // @Title 语音识别详情
  559. // @Description 语音识别详情
  560. // @Param SpeechRecognitionId query int true "语音识别ID"
  561. // @Success 200 {object} speech_recognition.SpeechRecognitionMenuNodeItem
  562. // @router /detail [get]
  563. func (this *SpeechRecognitionController) Detail() {
  564. br := new(models.BaseResponse).Init()
  565. defer func() {
  566. if br.ErrMsg == "" {
  567. br.IsSendEmail = false
  568. }
  569. this.Data["json"] = br
  570. this.ServeJSON()
  571. }()
  572. sysUser := this.SysUser
  573. if sysUser == nil {
  574. br.Msg = "请登录"
  575. br.ErrMsg = "请登录,SysUser Is Empty"
  576. br.Ret = 408
  577. return
  578. }
  579. // TODO:标签详情
  580. br.Ret = 200
  581. br.Success = true
  582. br.Msg = "获取成功"
  583. }
  584. // TODO:Move
  585. // @Title 移动语音识别/目录
  586. // @Description 移动标签/目录
  587. // @Param request body speech_recognition.SpeechRecognitionTagRemoveReq true "type json string"
  588. // @Success 200 string "操作成功"
  589. // @router /move [post]
  590. func (this *SpeechRecognitionController) Move() {
  591. br := new(models.BaseResponse).Init()
  592. defer func() {
  593. if br.ErrMsg == "" {
  594. br.IsSendEmail = false
  595. }
  596. this.Data["json"] = br
  597. this.ServeJSON()
  598. }()
  599. sysUser := this.SysUser
  600. if sysUser == nil {
  601. br.Msg = "请登录"
  602. br.ErrMsg = "请登录,SysUser Is Empty"
  603. br.Ret = 408
  604. return
  605. }
  606. // TODO:移动语音识别/目录
  607. br.Ret = 200
  608. br.Success = true
  609. br.Msg = "操作成功"
  610. }
  611. //// TestConvert
  612. //// @Title 转写测试
  613. //// @Description 转写测试
  614. //// @Param request body speech_recognition.SpeechRecognitionSaveReq true "type json string"
  615. //// @Success 200 string "操作成功"
  616. //// @router /test_convert [post]
  617. //func (this *SpeechRecognitionCommonController) TestConvert() {
  618. // br := new(models.BaseResponse).Init()
  619. // defer func() {
  620. // if br.ErrMsg == "" {
  621. // br.IsSendEmail = false
  622. // }
  623. // this.Data["json"] = br
  624. // this.ServeJSON()
  625. // }()
  626. // //sysUser := this.SysUser
  627. // //if sysUser == nil {
  628. // // br.Msg = "请登录"
  629. // // br.ErrMsg = "请登录,SysUser Is Empty"
  630. // // br.Ret = 408
  631. // // return
  632. // //}
  633. // var req speech_recognition.SpeechRecognitionSaveReq
  634. // if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
  635. // br.Msg = "参数有误"
  636. // br.ErrMsg = "参数解析失败, Err: " + e.Error()
  637. // return
  638. // }
  639. //
  640. // conf, e := models.GetBusinessConf()
  641. // if e != nil {
  642. // br.Msg = "操作失败"
  643. // br.ErrMsg = "获取配置失败, Err: " + e.Error()
  644. // return
  645. // }
  646. //
  647. // var taskReq services.TencentRecTaskReq
  648. // taskReq.FileUrl = req.FileName
  649. // taskReq.SecretId = conf[models.BusinessConfTencentApiSecretId]
  650. // taskReq.SecretKey = conf[models.BusinessConfTencentApiSecretKey]
  651. // taskReq.CallbackUrl = conf[models.BusinessConfTencentApiRecTaskCallbackUrl]
  652. // taskId, e := services.TencentCreateRecTask(taskReq)
  653. // if e != nil {
  654. // br.Msg = "操作失败"
  655. // br.ErrMsg = fmt.Sprintf("TencentCreateRecTask err: %s", e.Error())
  656. // return
  657. // }
  658. //
  659. // br.Data = taskId
  660. // br.Ret = 200
  661. // br.Success = true
  662. // br.Msg = "操作成功"
  663. //}