translation

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WebVTTFileHead      = "WEBVTT FILE\n\n"
	WebVTTContentFormat = "%d\n%s --> %s\n%s\n\n"
)

Variables

View Source
var (
	ErrRequestFailed       = errors.New("request failed")
	ErrTranslationNotMatch = errors.New("translation result length not match")
)
View Source
var (
	ErrRequestASRFailed = errors.New("request ASR failed")
	ErrRequestTTSFailed = errors.New("request TTS failed")
	ErrPathNotExisted   = errors.New("requested path is not existed")
)

Functions

This section is empty.

Types

type ASRRequest added in v1.0.0

type ASRRequest struct {
	AudioUrl string `json:"audioUrl"`
	Callback string `json:"callback"`
}

ASRRequest

type ASRResponse added in v1.0.0

type ASRResponse struct {
	Rtn      int    `json:"rtn"`
	Message  string `json:"message"`
	TaskId   string `json:"taskId"`
	AudioUrl string `json:"audio"`
}

ASRResponse

type ASRTaskData added in v1.0.0

type ASRTaskData Video2TextCallbackResponse

type Data added in v1.0.0

type Data struct {
	StatusCode   int          `json:"statusCode"`
	StatusText   string       `json:"statusText"`
	SpeechResult SpeechResult `json:"speechResult"`
}

Data is the data of Video2TextCallbackResponse

type Detail added in v1.0.0

type Detail struct {
	Sentences  string       `json:"sentences"`
	StartTime  string       `json:"startTime"`
	EndTime    string       `json:"endTime"`
	SpeakerId  string       `json:"speakerId"`
	WordsPiece []WordsPiece `json:"wordsPiece"`
}

Detail is the detail of SpeechResult

type Engine

type Engine struct {
	HTTPClient     NiuTransClient // http client for translation
	QiNiuSDKClient QiNiuSDKClient // qiniu client
	// contains filtered or unexported fields
}

Engine is the config of translation server

func New

func New(translationAPIKey string, qiniuAccessKey string, qiniuSecretKey string) *Engine

New create a new TranslateConfig

func (*Engine) GenerateWebVTTBytes added in v1.0.0

func (e *Engine) GenerateWebVTTBytes(asrTaskData ASRTaskData) (bytes.Buffer, error)

GenerateWebVTTBytes generate caption for speech result

func (*Engine) GenerateWebVTTBytesWithTranslation added in v1.0.0

func (e *Engine) GenerateWebVTTBytesWithTranslation(asrTaskData ASRTaskData, from, to language.Tag) (bytes.Buffer, error)

GenerateWebVTTBytesWithTranslation generate caption for speech result with translation

func (*Engine) GenerateWebVTTFile added in v1.0.0

func (e *Engine) GenerateWebVTTFile(asrTaskData ASRTaskData, path string) error

GenerateWebVTTFile generate caption for speech result

func (*Engine) GenerateWebVTTFileWithTranslation added in v1.0.0

func (e *Engine) GenerateWebVTTFileWithTranslation(asrTaskData ASRTaskData, path string, from, to language.Tag) error

GenerateWebVTTFileWithTranslation generate caption for speech result with translation

func (*Engine) QueryVideo2TextTask added in v1.0.0

func (e *Engine) QueryVideo2TextTask(taskId string) (*ASRTaskData, error)

QueryVideo2TextTask

func (*Engine) Text2Audio added in v1.0.0

func (e *Engine) Text2Audio(content string) (*TTSResponse, error)

Text2Audio

func (*Engine) TranslateBatchPlain

func (e *Engine) TranslateBatchPlain(src []string, from string, to language.Tag) ([]string, error)

TranslateBatchSeq translate a series of sequences of text

func (*Engine) TranslateMarkdown

func (e *Engine) TranslateMarkdown(src []byte, from string, to language.Tag) (ret []byte, err error)

TranslateMarkdown translate markdown with bytes

func (*Engine) TranslateMarkdownText

func (e *Engine) TranslateMarkdownText(src string, from string, to language.Tag) (ret string, err error)

TranslateMarkdown translate markdown text

func (*Engine) TranslatePlain

func (e *Engine) TranslatePlain(src []byte, from string, to language.Tag) (ret []byte, err error)

Translate translate sequence of bytes

func (*Engine) TranslatePlainText

func (e *Engine) TranslatePlainText(src string, from string, to language.Tag) (ret string, err error)

Translate translate sequence of text

func (*Engine) TranslateVideo added in v1.0.0

func (e *Engine) TranslateVideo(from, to language.Tag, src string, callback string) (*ASRResponse, error)

TranslateVideo translates video, return the url of translated video

func (*Engine) TranslateWebVTT added in v1.0.0

func (e *Engine) TranslateWebVTT(src *SimpleWebVTT, from string, to language.Tag) (err error)

TranslateWebVTT translate WebVTT

func (*Engine) Video2Text added in v1.0.0

func (e *Engine) Video2Text(src string, callback string) (*ASRResponse, error)

Video2Text

func (*Engine) Video2TextCallback added in v1.0.0

func (e *Engine) Video2TextCallback(callbackData Video2TextCallbackResponse) (string, error)

Video2TextCallback doc: https://developer.qiniu.com/dora/11175/long-speech-recognition

type NiuTransClient added in v1.0.0

type NiuTransClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient for translation, for mock

type QiNiuSDKClient added in v1.0.0

type QiNiuSDKClient interface {
	CredentialedCallWithJson(ctx context.Context, cred *auth.Credentials, tokenType auth.TokenType, ret interface{},
		method, reqUrl string, headers http.Header, param interface{}) error
}

QiNiuSDKClient for qiniu, for mock

type SimpleWebVTT added in v1.0.0

type SimpleWebVTT struct {
	WebVTTFileHead string
	Content        []SimpleWebVTTContent
}

SimpleWebVTT is the simple format of WebVTT

func GenerateSimpleWebVTTFileFromASRTaskData added in v1.0.0

func GenerateSimpleWebVTTFileFromASRTaskData(asrTaskData ASRTaskData) SimpleWebVTT

GenerateSimpleWebVTTFileFromASRTaskData generate simple WebVTT file from ASRTaskData

func NewSimpleWebVTT added in v1.0.0

func NewSimpleWebVTT(reader io.Reader) (SimpleWebVTT, error)

NewSimpleWebVTT create a new SimpleWebVTT from io.Reader

Example: Basic format WEBVTT FILE

1 00:00:09.500 --> 00:00:12.000 The ocean floor rises 5 miles to the shores

func (*SimpleWebVTT) AddContent added in v1.0.0

func (w *SimpleWebVTT) AddContent(index int, startTime, endTime, sentence string)

AddContent add content to SimpleWebVTT

func (*SimpleWebVTT) ToBuffer added in v1.0.0

func (w *SimpleWebVTT) ToBuffer() *bytes.Buffer

ToBuffer convert SimpleWebVTT to buffer

func (*SimpleWebVTT) ToString added in v1.0.0

func (w *SimpleWebVTT) ToString() string

ToString convert SimpleWebVTT to string

type SimpleWebVTTContent added in v1.0.0

type SimpleWebVTTContent struct {
	Index     int
	StartTime string
	EndTime   string
	Sentence  string
}

SimpleWebVTTContent is the content of SimpleWebVTT

type SpeechResult added in v1.0.0

type SpeechResult struct {
	ResultText string   `json:"resultText"`
	Duration   int      `json:"duration"`
	Detail     []Detail `json:"detail"`
}

SpeechResult is the speech result of Video2TextCallbackResponse

type TTSAudioResult added in v1.0.0

type TTSAudioResult struct {
	AudioUrl string `json:"audioUrl"`
}

TTSAudioResult is the result of TTS

type TTSRequest added in v1.0.0

type TTSRequest struct {
	Content string `json:"content"`
}

TTSRequest

type TTSResponse added in v1.0.0

type TTSResponse struct {
	Code   string         `json:"code"`
	Msg    string         `json:"msg"`
	Result TTSAudioResult `json:"result"`
}

TTSResponse is the response of TTS

type Video2TextCallbackResponse added in v1.0.0

type Video2TextCallbackResponse struct {
	Rtn       int    `json:"rtn"`
	Message   string `json:"message"`
	RequestId string `json:"requestId"`
	TaskId    string `json:"taskId"`
	Data      Data   `json:"data"`
}

Video2TextCallbackResponse

type WordsPiece added in v1.0.0

type WordsPiece struct {
	Words           string `json:"words"`
	StartTime       string `json:"startTime"`
	EndTime         string `json:"endTime"`
	TranscribedType string `json:"transcribedType"`
}

WordsPiece is the words piece of Detail

Jump to

Keyboard shortcuts

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