paraformer

package
v0.0.0-...-e1deba5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 29, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// real-time voice recognition.
	ParaformerWSURL = "wss://dashscope.aliyuncs.com/api-ws/v1/inference"
	// audio file to text.
	ParaformerAsyncURL = "https://dashscope.aliyuncs.com/api/v1/services/audio/asr/transcription"
	// audio file to text  async-task-result query.
	ParaformerTaskURL = "https://dashscope.aliyuncs.com/api/v1/tasks/%s"
)

Variables

This section is empty.

Functions

func CloseRecognitionClient

func CloseRecognitionClient(cli *httpclient.WsClient) error

func ConnRecognitionClient

func ConnRecognitionClient(request *Request, token string) (*httpclient.WsClient, error)

func GenerateTaskID

func GenerateTaskID() string

task_id length 32.

func HandleRecognitionResult

func HandleRecognitionResult(ctx context.Context, cli *httpclient.WsClient, fn StreamingFunc)

func SendRadioData

func SendRadioData(cli *httpclient.WsClient, bytesData []byte)

func TaskURL

func TaskURL(taskID string) string

Types

type AsyncInput

type AsyncInput struct {
	FileURLs                 []string `json:"file_urls"`
	VocabularyID             string   `json:"vocabulary_id,omitempty"`              // 热词表 ID.
	ChannelID                []int    `json:"channel_id,omitempty"`                 // 音轨索引.
	DisfluencyRemovalEnabled bool     `json:"disfluency_removal_enabled,omitempty"` // 过滤语气词.
	LanguageHints            []string `json:"language_hints,omitempty"`             // 识别语音中语言的代码列表. 仅对paraformer-v2生效
}

type AsyncTaskRequest

type AsyncTaskRequest struct {
	Model        string     `json:"model"`
	Input        AsyncInput `json:"input"`
	HasUploadOss bool       `json:"-"`
	Download     bool       `json:"-"`
}

=========== 生成异步 task_id.

type AsyncTaskResponse

type AsyncTaskResponse struct {
	RequestID string             `json:"request_id"`
	Output    TaskResultResponse `json:"output"`
}

func AsyncVoiceFileRecognitionTask

func AsyncVoiceFileRecognitionTask(ctx context.Context, request *AsyncTaskRequest, cli httpclient.IHttpClient, token string) (*AsyncTaskResponse, error)

func CheckTaskStatus

func CheckTaskStatus(ctx context.Context, req *TaskResultRequest, httpcli httpclient.IHttpClient, options ...httpclient.HTTPOption) (*AsyncTaskResponse, error)

type Attributes

type Attributes struct{}

type FileResult

type FileResult struct {
	FileURL     string       `json:"file_url"`
	Properties  Properties   `json:"properties"`
	Transcripts []Transcript `json:"transcripts"`
}

=========== 最终结果 ===========.

type Header struct {
	TaskID     string     `json:"task_id"`
	Event      string     `json:"event"`
	Attributes Attributes `json:"attributes"`
}

type ModelParaformer

type ModelParaformer = string
const (
	// detect from file.
	ParaformerV1    ModelParaformer = "paraformer-v1"
	Paraformer8KV1  ModelParaformer = "paraformer-8k-v1"
	ParaformerMtlV1 ModelParaformer = "paraformer-mtl-v1"
	ParaformerV2    ModelParaformer = "paraformer-v2"
	Paraformer8KV2  ModelParaformer = "paraformer-8k-v2"
	// real time voice.
	ParaformerRealTimeV1   ModelParaformer = "paraformer-realtime-v1"
	ParaformerRealTime8KV1 ModelParaformer = "paraformer-realtime-8k-v1"
	ParaformerRealTimeV2   ModelParaformer = "paraformer-realtime-v2"
	ParaformerRealTime8KV2 ModelParaformer = "paraformer-realtime-8k-v2"
)

type Output

type Output struct {
	Sentence Sentence `json:"sentence"`
}

type Parameters

type Parameters struct {
	SampleRate               int      `json:"sample_rate"`
	Format                   string   `json:"format"`
	DisfluencyRemovalEnabled bool     `json:"disfluency_removal_enabled"`
	LanguageHints            []string `json:"language_hints"`
}

type PayloadIn

type PayloadIn struct {
	Model      string                 `json:"model"`
	Parameters Parameters             `json:"parameters"`
	Input      map[string]interface{} `json:"input"`
	Task       string                 `json:"task"`
	TaskGroup  string                 `json:"task_group"`
	Function   string                 `json:"function"`
}

type PayloadOut

type PayloadOut struct {
	Output Output `json:"output"`
	Usage  Usage  `json:"usage"`
}

type Properties

type Properties struct {
	Channels                       []interface{} `json:"channels"`
	OriginalSamplingRate           int           `json:"original_sampling_rate"`
	OriginalDurationInMilliseconds int           `json:"original_duration_in_milliseconds"`
}

type RecognitionResult

type RecognitionResult struct {
	Header  Header     `json:"header"`
	Payload PayloadOut `json:"payload"`
}

type ReqHeader

type ReqHeader struct {
	Streaming string `json:"streaming"`
	TaskID    string `json:"task_id"`
	Action    string `json:"action"`
}

type Request

type Request struct {
	Header      ReqHeader     `json:"header"`
	Payload     PayloadIn     `json:"payload"`
	StreamingFn StreamingFunc `json:"-"`
}

type Result

type Result struct {
	FileURL          string `json:"file_url,omitempty"`
	TranscriptionURL string `json:"transcription_url,omitempty"`
	SubtaskStatus    string `json:"subtask_status,omitempty"`
}

type ResultWriter

type ResultWriter interface {
	WriteResult(str string) error
}

type Sentence

type Sentence struct {
	BeginTime  int    `json:"begin_time"`
	EndTime    int    `json:"end_time"`
	SentenceID int    `json:"sentence_id"`
	Text       string `json:"text"`
	Words      []Word `json:"words"`
}

type StreamingFunc

type StreamingFunc func(ctx context.Context, chunk []byte) error

type TaskMetrics

type TaskMetrics struct {
	Total     int `json:"TOTAL,omitempty"`
	Succeeded int `json:"SUCCEEDED,omitempty"`
	Failed    int `json:"FAILED,omitempty"`
}

type TaskResultRequest

type TaskResultRequest struct {
	TaskID string `json:"task_id"`
}

根据 task_id 获取结果.

type TaskResultResponse

type TaskResultResponse struct {
	TaskID        string      `json:"task_id,omitempty"`
	TaskStatus    string      `json:"task_status,omitempty"`
	SubmitTime    string      `json:"submit_time,omitempty"`
	ScheduledTime string      `json:"scheduled_time,omitempty"`
	EndTime       string      `json:"end_time,omitempty"`
	Results       []Result    `json:"results,omitempty"`
	TaskMetrics   TaskMetrics `json:"task_metrics,omitempty"`
}

type Transcript

type Transcript struct {
	ChannelID                     int        `json:"channel_id"`
	ContentDurationInMilliseconds int        `json:"content_duration_in_milliseconds"`
	Text                          string     `json:"text"`
	Sentences                     []Sentence `json:"sentences"`
}

type Usage

type Usage struct {
	Duration int `json:"duration"`
}

type VoiceFileResponse

type VoiceFileResponse struct {
	AsyncTaskResp *AsyncTaskResponse
	FileResults   []*FileResult
}

func VoiceFileToTextGeneration

func VoiceFileToTextGeneration(ctx context.Context, req *AsyncTaskRequest, cli httpclient.IHttpClient, token string) (*VoiceFileResponse, error)

type Word

type Word struct {
	BeginTime   int    `json:"begin_time"`
	EndTime     int    `json:"end_time"`
	Text        string `json:"text"`
	Punctuation string `json:"punctuation"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL