gitee.com/larksuite/oapi-sdk-go/v3@v3.0.3/service/speech_to_text/v1/model.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  	"gitee.com/larksuite/oapi-sdk-go/v3/core"
    18  )
    19  
    20  type FileConfig struct {
    21  	FileId     *string `json:"file_id,omitempty"`     // 仅包含字母数字和下划线的 16 位字符串作为文件的标识,用户生成
    22  	Format     *string `json:"format,omitempty"`      // 语音格式,目前仅支持:pcm
    23  	EngineType *string `json:"engine_type,omitempty"` // 引擎类型,目前仅支持:16k_auto 中英混合
    24  }
    25  
    26  type FileConfigBuilder struct {
    27  	fileId         string // 仅包含字母数字和下划线的 16 位字符串作为文件的标识,用户生成
    28  	fileIdFlag     bool
    29  	format         string // 语音格式,目前仅支持:pcm
    30  	formatFlag     bool
    31  	engineType     string // 引擎类型,目前仅支持:16k_auto 中英混合
    32  	engineTypeFlag bool
    33  }
    34  
    35  func NewFileConfigBuilder() *FileConfigBuilder {
    36  	builder := &FileConfigBuilder{}
    37  	return builder
    38  }
    39  
    40  // 仅包含字母数字和下划线的 16 位字符串作为文件的标识,用户生成
    41  //
    42  // 示例值:qwe12dd34567890w
    43  func (builder *FileConfigBuilder) FileId(fileId string) *FileConfigBuilder {
    44  	builder.fileId = fileId
    45  	builder.fileIdFlag = true
    46  	return builder
    47  }
    48  
    49  // 语音格式,目前仅支持:pcm
    50  //
    51  // 示例值:pcm
    52  func (builder *FileConfigBuilder) Format(format string) *FileConfigBuilder {
    53  	builder.format = format
    54  	builder.formatFlag = true
    55  	return builder
    56  }
    57  
    58  // 引擎类型,目前仅支持:16k_auto 中英混合
    59  //
    60  // 示例值:16k_auto
    61  func (builder *FileConfigBuilder) EngineType(engineType string) *FileConfigBuilder {
    62  	builder.engineType = engineType
    63  	builder.engineTypeFlag = true
    64  	return builder
    65  }
    66  
    67  func (builder *FileConfigBuilder) Build() *FileConfig {
    68  	req := &FileConfig{}
    69  	if builder.fileIdFlag {
    70  		req.FileId = &builder.fileId
    71  
    72  	}
    73  	if builder.formatFlag {
    74  		req.Format = &builder.format
    75  
    76  	}
    77  	if builder.engineTypeFlag {
    78  		req.EngineType = &builder.engineType
    79  
    80  	}
    81  	return req
    82  }
    83  
    84  type Speech struct {
    85  	Speech    *string `json:"speech,omitempty"`     // pcm格式音频文件(文件识别)或音频分片(流式识别)经base64编码后的内容
    86  	SpeechKey *string `json:"speech_key,omitempty"` // 上传到 drive 存储平台后获取到的 key (暂不支持)
    87  }
    88  
    89  type SpeechBuilder struct {
    90  	speech        string // pcm格式音频文件(文件识别)或音频分片(流式识别)经base64编码后的内容
    91  	speechFlag    bool
    92  	speechKey     string // 上传到 drive 存储平台后获取到的 key (暂不支持)
    93  	speechKeyFlag bool
    94  }
    95  
    96  func NewSpeechBuilder() *SpeechBuilder {
    97  	builder := &SpeechBuilder{}
    98  	return builder
    99  }
   100  
   101  // pcm格式音频文件(文件识别)或音频分片(流式识别)经base64编码后的内容
   102  //
   103  // 示例值:PdmrfE267Cd/Z9KpmNFh71A2PSJZxSp7+8upCg==
   104  func (builder *SpeechBuilder) Speech(speech string) *SpeechBuilder {
   105  	builder.speech = speech
   106  	builder.speechFlag = true
   107  	return builder
   108  }
   109  
   110  // 上传到 drive 存储平台后获取到的 key (暂不支持)
   111  //
   112  // 示例值:
   113  func (builder *SpeechBuilder) SpeechKey(speechKey string) *SpeechBuilder {
   114  	builder.speechKey = speechKey
   115  	builder.speechKeyFlag = true
   116  	return builder
   117  }
   118  
   119  func (builder *SpeechBuilder) Build() *Speech {
   120  	req := &Speech{}
   121  	if builder.speechFlag {
   122  		req.Speech = &builder.speech
   123  
   124  	}
   125  	if builder.speechKeyFlag {
   126  		req.SpeechKey = &builder.speechKey
   127  
   128  	}
   129  	return req
   130  }
   131  
   132  type StreamConfig struct {
   133  	StreamId   *string `json:"stream_id,omitempty"`   // 仅包含字母数字和下划线的 16 位字符串作为同一数据流的标识,用户生成
   134  	SequenceId *int    `json:"sequence_id,omitempty"` // 数据流分片的序号,序号从 0 开始,每次请求递增 1
   135  	Action     *int    `json:"action,omitempty"`      // 数据流标记:1 首包,2 正常结束,等待结果返回,3 中断数据流不返回最终结果
   136  	Format     *string `json:"format,omitempty"`      // 语音格式,目前仅支持:pcm
   137  	EngineType *string `json:"engine_type,omitempty"` // 引擎类型,目前仅支持:16k_auto 中英混合
   138  }
   139  
   140  type StreamConfigBuilder struct {
   141  	streamId       string // 仅包含字母数字和下划线的 16 位字符串作为同一数据流的标识,用户生成
   142  	streamIdFlag   bool
   143  	sequenceId     int // 数据流分片的序号,序号从 0 开始,每次请求递增 1
   144  	sequenceIdFlag bool
   145  	action         int // 数据流标记:1 首包,2 正常结束,等待结果返回,3 中断数据流不返回最终结果
   146  	actionFlag     bool
   147  	format         string // 语音格式,目前仅支持:pcm
   148  	formatFlag     bool
   149  	engineType     string // 引擎类型,目前仅支持:16k_auto 中英混合
   150  	engineTypeFlag bool
   151  }
   152  
   153  func NewStreamConfigBuilder() *StreamConfigBuilder {
   154  	builder := &StreamConfigBuilder{}
   155  	return builder
   156  }
   157  
   158  // 仅包含字母数字和下划线的 16 位字符串作为同一数据流的标识,用户生成
   159  //
   160  // 示例值:asd1234567890ddd
   161  func (builder *StreamConfigBuilder) StreamId(streamId string) *StreamConfigBuilder {
   162  	builder.streamId = streamId
   163  	builder.streamIdFlag = true
   164  	return builder
   165  }
   166  
   167  // 数据流分片的序号,序号从 0 开始,每次请求递增 1
   168  //
   169  // 示例值:1
   170  func (builder *StreamConfigBuilder) SequenceId(sequenceId int) *StreamConfigBuilder {
   171  	builder.sequenceId = sequenceId
   172  	builder.sequenceIdFlag = true
   173  	return builder
   174  }
   175  
   176  // 数据流标记:1 首包,2 正常结束,等待结果返回,3 中断数据流不返回最终结果
   177  //
   178  // 示例值:1
   179  func (builder *StreamConfigBuilder) Action(action int) *StreamConfigBuilder {
   180  	builder.action = action
   181  	builder.actionFlag = true
   182  	return builder
   183  }
   184  
   185  // 语音格式,目前仅支持:pcm
   186  //
   187  // 示例值:pcm
   188  func (builder *StreamConfigBuilder) Format(format string) *StreamConfigBuilder {
   189  	builder.format = format
   190  	builder.formatFlag = true
   191  	return builder
   192  }
   193  
   194  // 引擎类型,目前仅支持:16k_auto 中英混合
   195  //
   196  // 示例值:16k_auto
   197  func (builder *StreamConfigBuilder) EngineType(engineType string) *StreamConfigBuilder {
   198  	builder.engineType = engineType
   199  	builder.engineTypeFlag = true
   200  	return builder
   201  }
   202  
   203  func (builder *StreamConfigBuilder) Build() *StreamConfig {
   204  	req := &StreamConfig{}
   205  	if builder.streamIdFlag {
   206  		req.StreamId = &builder.streamId
   207  
   208  	}
   209  	if builder.sequenceIdFlag {
   210  		req.SequenceId = &builder.sequenceId
   211  
   212  	}
   213  	if builder.actionFlag {
   214  		req.Action = &builder.action
   215  
   216  	}
   217  	if builder.formatFlag {
   218  		req.Format = &builder.format
   219  
   220  	}
   221  	if builder.engineTypeFlag {
   222  		req.EngineType = &builder.engineType
   223  
   224  	}
   225  	return req
   226  }
   227  
   228  type FileRecognizeSpeechReqBodyBuilder struct {
   229  	speech     *Speech // 语音资源
   230  	speechFlag bool
   231  	config     *FileConfig // 配置属性
   232  	configFlag bool
   233  }
   234  
   235  func NewFileRecognizeSpeechReqBodyBuilder() *FileRecognizeSpeechReqBodyBuilder {
   236  	builder := &FileRecognizeSpeechReqBodyBuilder{}
   237  	return builder
   238  }
   239  
   240  // 语音资源
   241  //
   242  //示例值:
   243  func (builder *FileRecognizeSpeechReqBodyBuilder) Speech(speech *Speech) *FileRecognizeSpeechReqBodyBuilder {
   244  	builder.speech = speech
   245  	builder.speechFlag = true
   246  	return builder
   247  }
   248  
   249  // 配置属性
   250  //
   251  //示例值:
   252  func (builder *FileRecognizeSpeechReqBodyBuilder) Config(config *FileConfig) *FileRecognizeSpeechReqBodyBuilder {
   253  	builder.config = config
   254  	builder.configFlag = true
   255  	return builder
   256  }
   257  
   258  func (builder *FileRecognizeSpeechReqBodyBuilder) Build() *FileRecognizeSpeechReqBody {
   259  	req := &FileRecognizeSpeechReqBody{}
   260  	if builder.speechFlag {
   261  		req.Speech = builder.speech
   262  	}
   263  	if builder.configFlag {
   264  		req.Config = builder.config
   265  	}
   266  	return req
   267  }
   268  
   269  type FileRecognizeSpeechPathReqBodyBuilder struct {
   270  	speech     *Speech // 语音资源
   271  	speechFlag bool
   272  	config     *FileConfig // 配置属性
   273  	configFlag bool
   274  }
   275  
   276  func NewFileRecognizeSpeechPathReqBodyBuilder() *FileRecognizeSpeechPathReqBodyBuilder {
   277  	builder := &FileRecognizeSpeechPathReqBodyBuilder{}
   278  	return builder
   279  }
   280  
   281  // 语音资源
   282  //
   283  // 示例值:
   284  func (builder *FileRecognizeSpeechPathReqBodyBuilder) Speech(speech *Speech) *FileRecognizeSpeechPathReqBodyBuilder {
   285  	builder.speech = speech
   286  	builder.speechFlag = true
   287  	return builder
   288  }
   289  
   290  // 配置属性
   291  //
   292  // 示例值:
   293  func (builder *FileRecognizeSpeechPathReqBodyBuilder) Config(config *FileConfig) *FileRecognizeSpeechPathReqBodyBuilder {
   294  	builder.config = config
   295  	builder.configFlag = true
   296  	return builder
   297  }
   298  
   299  func (builder *FileRecognizeSpeechPathReqBodyBuilder) Build() (*FileRecognizeSpeechReqBody, error) {
   300  	req := &FileRecognizeSpeechReqBody{}
   301  	if builder.speechFlag {
   302  		req.Speech = builder.speech
   303  	}
   304  	if builder.configFlag {
   305  		req.Config = builder.config
   306  	}
   307  	return req, nil
   308  }
   309  
   310  type FileRecognizeSpeechReqBuilder struct {
   311  	apiReq *larkcore.ApiReq
   312  	body   *FileRecognizeSpeechReqBody
   313  }
   314  
   315  func NewFileRecognizeSpeechReqBuilder() *FileRecognizeSpeechReqBuilder {
   316  	builder := &FileRecognizeSpeechReqBuilder{}
   317  	builder.apiReq = &larkcore.ApiReq{
   318  		PathParams:  larkcore.PathParams{},
   319  		QueryParams: larkcore.QueryParams{},
   320  	}
   321  	return builder
   322  }
   323  
   324  // 语音文件识别接口,上传整段语音文件进行一次性识别。接口适合 60 秒以内音频识别
   325  func (builder *FileRecognizeSpeechReqBuilder) Body(body *FileRecognizeSpeechReqBody) *FileRecognizeSpeechReqBuilder {
   326  	builder.body = body
   327  	return builder
   328  }
   329  
   330  func (builder *FileRecognizeSpeechReqBuilder) Build() *FileRecognizeSpeechReq {
   331  	req := &FileRecognizeSpeechReq{}
   332  	req.apiReq = &larkcore.ApiReq{}
   333  	req.apiReq.Body = builder.body
   334  	return req
   335  }
   336  
   337  type FileRecognizeSpeechReqBody struct {
   338  	Speech *Speech     `json:"speech,omitempty"` // 语音资源
   339  	Config *FileConfig `json:"config,omitempty"` // 配置属性
   340  }
   341  
   342  type FileRecognizeSpeechReq struct {
   343  	apiReq *larkcore.ApiReq
   344  	Body   *FileRecognizeSpeechReqBody `body:""`
   345  }
   346  
   347  type FileRecognizeSpeechRespData struct {
   348  	RecognitionText *string `json:"recognition_text,omitempty"` // 语音识别后的文本信息
   349  }
   350  
   351  type FileRecognizeSpeechResp struct {
   352  	*larkcore.ApiResp `json:"-"`
   353  	larkcore.CodeError
   354  	Data *FileRecognizeSpeechRespData `json:"data"` // 业务数据
   355  }
   356  
   357  func (resp *FileRecognizeSpeechResp) Success() bool {
   358  	return resp.Code == 0
   359  }
   360  
   361  type StreamRecognizeSpeechReqBodyBuilder struct {
   362  	speech     *Speech // 语音资源
   363  	speechFlag bool
   364  	config     *StreamConfig // 配置属性
   365  	configFlag bool
   366  }
   367  
   368  func NewStreamRecognizeSpeechReqBodyBuilder() *StreamRecognizeSpeechReqBodyBuilder {
   369  	builder := &StreamRecognizeSpeechReqBodyBuilder{}
   370  	return builder
   371  }
   372  
   373  // 语音资源
   374  //
   375  //示例值:
   376  func (builder *StreamRecognizeSpeechReqBodyBuilder) Speech(speech *Speech) *StreamRecognizeSpeechReqBodyBuilder {
   377  	builder.speech = speech
   378  	builder.speechFlag = true
   379  	return builder
   380  }
   381  
   382  // 配置属性
   383  //
   384  //示例值:
   385  func (builder *StreamRecognizeSpeechReqBodyBuilder) Config(config *StreamConfig) *StreamRecognizeSpeechReqBodyBuilder {
   386  	builder.config = config
   387  	builder.configFlag = true
   388  	return builder
   389  }
   390  
   391  func (builder *StreamRecognizeSpeechReqBodyBuilder) Build() *StreamRecognizeSpeechReqBody {
   392  	req := &StreamRecognizeSpeechReqBody{}
   393  	if builder.speechFlag {
   394  		req.Speech = builder.speech
   395  	}
   396  	if builder.configFlag {
   397  		req.Config = builder.config
   398  	}
   399  	return req
   400  }
   401  
   402  type StreamRecognizeSpeechPathReqBodyBuilder struct {
   403  	speech     *Speech // 语音资源
   404  	speechFlag bool
   405  	config     *StreamConfig // 配置属性
   406  	configFlag bool
   407  }
   408  
   409  func NewStreamRecognizeSpeechPathReqBodyBuilder() *StreamRecognizeSpeechPathReqBodyBuilder {
   410  	builder := &StreamRecognizeSpeechPathReqBodyBuilder{}
   411  	return builder
   412  }
   413  
   414  // 语音资源
   415  //
   416  // 示例值:
   417  func (builder *StreamRecognizeSpeechPathReqBodyBuilder) Speech(speech *Speech) *StreamRecognizeSpeechPathReqBodyBuilder {
   418  	builder.speech = speech
   419  	builder.speechFlag = true
   420  	return builder
   421  }
   422  
   423  // 配置属性
   424  //
   425  // 示例值:
   426  func (builder *StreamRecognizeSpeechPathReqBodyBuilder) Config(config *StreamConfig) *StreamRecognizeSpeechPathReqBodyBuilder {
   427  	builder.config = config
   428  	builder.configFlag = true
   429  	return builder
   430  }
   431  
   432  func (builder *StreamRecognizeSpeechPathReqBodyBuilder) Build() (*StreamRecognizeSpeechReqBody, error) {
   433  	req := &StreamRecognizeSpeechReqBody{}
   434  	if builder.speechFlag {
   435  		req.Speech = builder.speech
   436  	}
   437  	if builder.configFlag {
   438  		req.Config = builder.config
   439  	}
   440  	return req, nil
   441  }
   442  
   443  type StreamRecognizeSpeechReqBuilder struct {
   444  	apiReq *larkcore.ApiReq
   445  	body   *StreamRecognizeSpeechReqBody
   446  }
   447  
   448  func NewStreamRecognizeSpeechReqBuilder() *StreamRecognizeSpeechReqBuilder {
   449  	builder := &StreamRecognizeSpeechReqBuilder{}
   450  	builder.apiReq = &larkcore.ApiReq{
   451  		PathParams:  larkcore.PathParams{},
   452  		QueryParams: larkcore.QueryParams{},
   453  	}
   454  	return builder
   455  }
   456  
   457  // 语音流式接口,将整个音频文件分片进行传入模型。能够实时返回数据。建议每个音频分片的大小为 100-200ms
   458  func (builder *StreamRecognizeSpeechReqBuilder) Body(body *StreamRecognizeSpeechReqBody) *StreamRecognizeSpeechReqBuilder {
   459  	builder.body = body
   460  	return builder
   461  }
   462  
   463  func (builder *StreamRecognizeSpeechReqBuilder) Build() *StreamRecognizeSpeechReq {
   464  	req := &StreamRecognizeSpeechReq{}
   465  	req.apiReq = &larkcore.ApiReq{}
   466  	req.apiReq.Body = builder.body
   467  	return req
   468  }
   469  
   470  type StreamRecognizeSpeechReqBody struct {
   471  	Speech *Speech       `json:"speech,omitempty"` // 语音资源
   472  	Config *StreamConfig `json:"config,omitempty"` // 配置属性
   473  }
   474  
   475  type StreamRecognizeSpeechReq struct {
   476  	apiReq *larkcore.ApiReq
   477  	Body   *StreamRecognizeSpeechReqBody `body:""`
   478  }
   479  
   480  type StreamRecognizeSpeechRespData struct {
   481  	StreamId        *string `json:"stream_id,omitempty"`        // 16 位 String 随机串作为同一数据流的标识
   482  	SequenceId      *int    `json:"sequence_id,omitempty"`      // 数据流分片的序号,序号从 0 开始,每次请求递增 1
   483  	RecognitionText *string `json:"recognition_text,omitempty"` // 语音流识别后的文本信息
   484  }
   485  
   486  type StreamRecognizeSpeechResp struct {
   487  	*larkcore.ApiResp `json:"-"`
   488  	larkcore.CodeError
   489  	Data *StreamRecognizeSpeechRespData `json:"data"` // 业务数据
   490  }
   491  
   492  func (resp *StreamRecognizeSpeechResp) Success() bool {
   493  	return resp.Code == 0
   494  }