gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/service/speech_to_text/v1/api.go (about) 1 // Package speech_to_text code generated by oapi sdk gen 2 /* 3 * MIT License 4 * 5 * Copyright (c) 2022 Lark Technologies Pte. Ltd. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 8 * 9 * The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 12 */ 13 14 package larkspeech_to_text 15 16 import ( 17 "context" 18 "net/http" 19 20 "gitee.com/larksuite/oapi-sdk-go/v3/core" 21 ) 22 23 func NewService(config *larkcore.Config) *SpeechToTextService { 24 s := &SpeechToTextService{config: config} 25 s.Speech = &speech{service: s} 26 return s 27 } 28 29 type SpeechToTextService struct { 30 config *larkcore.Config 31 Speech *speech // 语音识别 32 } 33 34 type speech struct { 35 service *SpeechToTextService 36 } 37 38 // 语音文件识别 (ASR) 39 // 40 // - 语音文件识别接口,上传整段语音文件进行一次性识别。接口适合 60 秒以内音频识别 41 // 42 // - 单租户限流:20QPS,同租户下的应用没有限流,共享本租户的 20QPS 限流 43 // 44 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/ai/speech_to_text-v1/speech/file_recognize 45 // 46 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/speech_to_textv1/fileRecognize_speech.go 47 func (s *speech) FileRecognize(ctx context.Context, req *FileRecognizeSpeechReq, options ...larkcore.RequestOptionFunc) (*FileRecognizeSpeechResp, error) { 48 // 发起请求 49 apiReq := req.apiReq 50 apiReq.ApiPath = "/open-apis/speech_to_text/v1/speech/file_recognize" 51 apiReq.HttpMethod = http.MethodPost 52 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 53 apiResp, err := larkcore.Request(ctx, apiReq, s.service.config, options...) 54 if err != nil { 55 return nil, err 56 } 57 // 反序列响应结果 58 resp := &FileRecognizeSpeechResp{ApiResp: apiResp} 59 err = apiResp.JSONUnmarshalBody(resp) 60 if err != nil { 61 return nil, err 62 } 63 return resp, err 64 } 65 66 // 语音流式识别 (ASR) 67 // 68 // - 语音流式接口,将整个音频文件分片进行传入模型。能够实时返回数据。建议每个音频分片的大小为 100-200ms 69 // 70 // - 单租户限流:20 路(一个 stream_id 称为一路会话),同租户下的应用没有限流,共享本租户的 20路限流 71 // 72 // - 官网API文档链接:https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/ai/speech_to_text-v1/speech/stream_recognize 73 // 74 // - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/speech_to_textv1/streamRecognize_speech.go 75 func (s *speech) StreamRecognize(ctx context.Context, req *StreamRecognizeSpeechReq, options ...larkcore.RequestOptionFunc) (*StreamRecognizeSpeechResp, error) { 76 // 发起请求 77 apiReq := req.apiReq 78 apiReq.ApiPath = "/open-apis/speech_to_text/v1/speech/stream_recognize" 79 apiReq.HttpMethod = http.MethodPost 80 apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{larkcore.AccessTokenTypeTenant} 81 apiResp, err := larkcore.Request(ctx, apiReq, s.service.config, options...) 82 if err != nil { 83 return nil, err 84 } 85 // 反序列响应结果 86 resp := &StreamRecognizeSpeechResp{ApiResp: apiResp} 87 err = apiResp.JSONUnmarshalBody(resp) 88 if err != nil { 89 return nil, err 90 } 91 return resp, err 92 }