| | |
| | | BoolTypeTrue BoolType = 1 // true |
| | | BoolTypeFalse BoolType = 2 // false |
| | | ) |
| | | |
| | | func (slf BoolType) IsValid() bool { |
| | | return slf == BoolTypeTrue || slf == BoolTypeFalse |
| | | } |
| | | |
| | | func (slf BoolType) Bool() bool { |
| | | return slf == BoolTypeTrue |
| | | } |
| | |
| | | "speechAnalysis/models" |
| | | "speechAnalysis/pkg/logx" |
| | | "speechAnalysis/request" |
| | | "speechAnalysis/response" |
| | | "speechAnalysis/service" |
| | | "speechAnalysis/utils/upload" |
| | | "strings" |
| | |
| | | // @Tags 音频 |
| | | // @Summary 音频分析检索 |
| | | // @Produce application/json |
| | | // @Param object query request.GetAudioList true "查询参数" |
| | | // @Param object query request.GetAudioList true "参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.Audio} "成功" |
| | | // @Router /api-sa/v1/audio/list [get] |
| | | func (slf AudioCtl) List(c *gin.Context) { |
| | |
| | | // @Tags 音频 |
| | | // @Summary 处理音频 |
| | | // @Produce application/json |
| | | // @Param object body request.ProcessAudio true "音频信息" |
| | | // @Param object body request.ProcessAudio true "参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-sa/v1/audio/process [post] |
| | | func (slf AudioCtl) Process(c *gin.Context) { |
| | |
| | | // @Tags 音频 |
| | | // @Summary 批量处理音频 |
| | | // @Produce application/json |
| | | // @Param object body request.BatchProcessAudio true "音频信息" |
| | | // @Param object body request.BatchProcessAudio true "参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-sa/v1/audio/batchProcess [post] |
| | | func (slf AudioCtl) BatchProcess(c *gin.Context) { |
| | |
| | | // @Tags 音频 |
| | | // @Summary 删除音频 |
| | | // @Produce application/json |
| | | // @Param object body request.ProcessAudio true "音频信息" |
| | | // @Param object body request.ProcessAudio true "参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-sa/v1/audio/delete [post] |
| | | func (slf AudioCtl) Delete(c *gin.Context) { |
| | |
| | | // @Tags 音频 |
| | | // @Summary 批量删除音频 |
| | | // @Produce application/json |
| | | // @Param object body request.BatchProcessAudio true "音频信息" |
| | | // @Param object body request.BatchProcessAudio true "参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-sa/v1/audio/batchDelete [post] |
| | | func (slf AudioCtl) BatchDelete(c *gin.Context) { |
| | |
| | | |
| | | util.ResponseFormat(c, code.DeleteSuccess, "成功") |
| | | } |
| | | |
| | | // Follow |
| | | // @Tags 音频 |
| | | // @Summary 关注/取消关注 |
| | | // @Produce application/json |
| | | // @Param object body request.FollowReq true "参数" |
| | | // @Success 200 {object} util.Response{data=response.FollowResp} "成功" |
| | | // @Router /api-sa/v1/audio/follow [post] |
| | | func (slf AudioCtl) Follow(c *gin.Context) { |
| | | var params request.ProcessAudio |
| | | if err := c.ShouldBind(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | followStatus, err := service.Follow(params.ID) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.InternalError, err.Error()) |
| | | return |
| | | } |
| | | resp := response.FollowResp{FollowStatus: followStatus} |
| | | |
| | | util.ResponseFormat(c, code.UpdateSuccess, resp) |
| | | } |
| | |
| | | "summary": "批量删除音频", |
| | | "parameters": [ |
| | | { |
| | | "description": "音频信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "summary": "批量处理音频", |
| | | "parameters": [ |
| | | { |
| | | "description": "音频信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "summary": "删除音频", |
| | | "parameters": [ |
| | | { |
| | | "description": "音频信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/audio/follow": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "音频" |
| | | ], |
| | | "summary": "关注/取消关注", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.FollowReq" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.FollowResp" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | |
| | | "summary": "处理音频", |
| | | "parameters": [ |
| | | { |
| | | "description": "音频信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "occurrenceTime": { |
| | | "type": "string" |
| | | }, |
| | | "score": { |
| | | "description": "置信度", |
| | | "type": "number" |
| | | }, |
| | | "size": { |
| | | "description": "音频大小", |
| | | "type": "integer" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.FollowReq": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.ProcessAudio": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.FollowResp": { |
| | | "type": "object", |
| | | "properties": { |
| | | "followStatus": { |
| | | "$ref": "#/definitions/constvar.BoolType" |
| | | } |
| | | } |
| | | }, |
| | | "util.Response": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | "summary": "批量删除音频", |
| | | "parameters": [ |
| | | { |
| | | "description": "音频信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "summary": "批量处理音频", |
| | | "parameters": [ |
| | | { |
| | | "description": "音频信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "summary": "删除音频", |
| | | "parameters": [ |
| | | { |
| | | "description": "音频信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "description": "成功", |
| | | "schema": { |
| | | "$ref": "#/definitions/util.Response" |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | "/api-sa/v1/audio/follow": { |
| | | "post": { |
| | | "produces": [ |
| | | "application/json" |
| | | ], |
| | | "tags": [ |
| | | "音频" |
| | | ], |
| | | "summary": "关注/取消关注", |
| | | "parameters": [ |
| | | { |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | | "schema": { |
| | | "$ref": "#/definitions/request.FollowReq" |
| | | } |
| | | } |
| | | ], |
| | | "responses": { |
| | | "200": { |
| | | "description": "成功", |
| | | "schema": { |
| | | "allOf": [ |
| | | { |
| | | "$ref": "#/definitions/util.Response" |
| | | }, |
| | | { |
| | | "type": "object", |
| | | "properties": { |
| | | "data": { |
| | | "$ref": "#/definitions/response.FollowResp" |
| | | } |
| | | } |
| | | } |
| | | ] |
| | | } |
| | | } |
| | | } |
| | |
| | | "summary": "处理音频", |
| | | "parameters": [ |
| | | { |
| | | "description": "音频信息", |
| | | "description": "参数", |
| | | "name": "object", |
| | | "in": "body", |
| | | "required": true, |
| | |
| | | "occurrenceTime": { |
| | | "type": "string" |
| | | }, |
| | | "score": { |
| | | "description": "置信度", |
| | | "type": "number" |
| | | }, |
| | | "size": { |
| | | "description": "音频大小", |
| | | "type": "integer" |
| | |
| | | } |
| | | } |
| | | }, |
| | | "request.FollowReq": { |
| | | "type": "object", |
| | | "required": [ |
| | | "id" |
| | | ], |
| | | "properties": { |
| | | "id": { |
| | | "type": "integer" |
| | | } |
| | | } |
| | | }, |
| | | "request.ProcessAudio": { |
| | | "type": "object", |
| | | "required": [ |
| | |
| | | } |
| | | } |
| | | }, |
| | | "response.FollowResp": { |
| | | "type": "object", |
| | | "properties": { |
| | | "followStatus": { |
| | | "$ref": "#/definitions/constvar.BoolType" |
| | | } |
| | | } |
| | | }, |
| | | "util.Response": { |
| | | "type": "object", |
| | | "properties": { |
| | |
| | | type: string |
| | | occurrenceTime: |
| | | type: string |
| | | score: |
| | | description: 置信度 |
| | | type: number |
| | | size: |
| | | description: 音频大小 |
| | | type: integer |
| | |
| | | required: |
| | | - ids |
| | | type: object |
| | | request.FollowReq: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | required: |
| | | - id |
| | | type: object |
| | | request.ProcessAudio: |
| | | properties: |
| | | id: |
| | | type: integer |
| | | required: |
| | | - id |
| | | type: object |
| | | response.FollowResp: |
| | | properties: |
| | | followStatus: |
| | | $ref: '#/definitions/constvar.BoolType' |
| | | type: object |
| | | util.Response: |
| | | properties: |
| | |
| | | /api-sa/v1/audio/batchDelete: |
| | | post: |
| | | parameters: |
| | | - description: 音频信息 |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | |
| | | /api-sa/v1/audio/batchProcess: |
| | | post: |
| | | parameters: |
| | | - description: 音频信息 |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | |
| | | /api-sa/v1/audio/delete: |
| | | post: |
| | | parameters: |
| | | - description: 音频信息 |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | |
| | | schema: |
| | | $ref: '#/definitions/util.Response' |
| | | summary: 删除音频 |
| | | tags: |
| | | - 音频 |
| | | /api-sa/v1/audio/follow: |
| | | post: |
| | | parameters: |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | | schema: |
| | | $ref: '#/definitions/request.FollowReq' |
| | | produces: |
| | | - application/json |
| | | responses: |
| | | "200": |
| | | description: 成功 |
| | | schema: |
| | | allOf: |
| | | - $ref: '#/definitions/util.Response' |
| | | - properties: |
| | | data: |
| | | $ref: '#/definitions/response.FollowResp' |
| | | type: object |
| | | summary: 关注/取消关注 |
| | | tags: |
| | | - 音频 |
| | | /api-sa/v1/audio/list: |
| | |
| | | /api-sa/v1/audio/process: |
| | | post: |
| | | parameters: |
| | | - description: 音频信息 |
| | | - description: 参数 |
| | | in: body |
| | | name: object |
| | | required: true |
| | |
| | | OccurrenceAt time.Time `json:"-"` |
| | | OccurrenceTime string `json:"occurrenceTime" gorm:"-"` |
| | | IsFollowed constvar.BoolType `gorm:"type:tinyint;not null;default:2;comment:是否关注"` //是否关注 1关注 2未关注 |
| | | Score float64 `json:"score"` // 置信度 |
| | | } |
| | | |
| | | AudioSearch struct { |
| | |
| | | // AudioText 音频文本 |
| | | AudioText struct { |
| | | gorm.Model |
| | | AudioID uint `gorm:"unique;type:int;not null;default:0;comment:音频id" json:"audioID"` // 音频id |
| | | AudioText string `json:"audioText"` // 音频文本 |
| | | Score float64 `json:"score"` // 置信度 |
| | | AudioID uint `gorm:"unique;type:int;not null;default:0;comment:音频id" json:"audioID"` // 音频id |
| | | AudioText string `json:"audioText"` // 音频文本 |
| | | } |
| | | |
| | | AudioTextSearch struct { |
| | |
| | | type BatchProcessAudio struct { |
| | | IDs []uint `json:"ids" binding:"required"` |
| | | } |
| | | |
| | | type FollowReq struct { |
| | | ID uint `json:"id" binding:"required"` |
| | | } |
New file |
| | |
| | | package response |
| | | |
| | | import "speechAnalysis/constvar" |
| | | |
| | | type FollowResp struct { |
| | | FollowStatus constvar.BoolType `json:"followStatus"` |
| | | } |
| | |
| | | organizeAPI.POST("batchProcess", AudioCtl.BatchProcess) // 音频批量处理 |
| | | organizeAPI.POST("delete", AudioCtl.Delete) // 音频删除 |
| | | organizeAPI.POST("batchDelete", AudioCtl.BatchDelete) // 音频批量删除 |
| | | organizeAPI.POST("follow", AudioCtl.Follow) // 关注/取消关注 |
| | | } |
| | | |
| | | return r |
| | |
| | | import ( |
| | | "errors" |
| | | "gorm.io/gorm" |
| | | "speechAnalysis/constvar" |
| | | "speechAnalysis/models" |
| | | "speechAnalysis/pkg/logx" |
| | | ) |
| | |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func Follow(audioId uint) (followStatus constvar.BoolType, err error) { |
| | | if audioId == 0 { |
| | | return |
| | | } |
| | | audio, err := models.NewAudioSearch().SetID(audioId).First() |
| | | if err != nil { |
| | | return followStatus, errors.New("DB错误") |
| | | } |
| | | if audio.IsFollowed.Bool() { |
| | | followStatus = constvar.BoolTypeFalse |
| | | } else { |
| | | followStatus = constvar.BoolTypeTrue |
| | | } |
| | | err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{ |
| | | "is_followed": followStatus, |
| | | }) |
| | | if err != nil { |
| | | logx.Errorf("follow audio err: %v", err) |
| | | return followStatus, errors.New("DB错误") |
| | | } |
| | | return followStatus, nil |
| | | } |
| | |
| | | } |
| | | logx.Infof("AnalysisAudio result: %v", resp) |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{"audio_status": constvar.AudioStatusFinish}) |
| | | err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{ |
| | | "audio_status": constvar.AudioStatusFinish, |
| | | "score": resp.Score, |
| | | }) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | err = models.NewAudioTextSearch().Save(&models.AudioText{ |
| | | AudioID: audio.ID, |
| | | AudioText: resp.Result, |
| | | Score: resp.Score, |
| | | }) |
| | | return err |
| | | }) |