revai

package module
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 14 Imported by: 0

README

Go Rev.ai

Go Report Card GoDoc

A Rev.ai Go client library.

Installation

Install revai-go with:

go get -u github.com/descriptinc/revai-go

Then, import it using:

import (
    "github.com/descriptinc/revai-go"
)

Documentation

For details on all the functionality in this library, see the GoDoc documentation.

Below are a few simple examples:

New Client
// default client
c := revai.NewClient("API-KEY")
New Client With Options
httpClient := &http.Client{
    Timeout: 30 * time.Second,
}

c := revai.NewClient(
    "API_KEY",
    revai.HTTPClient(httpClient),
    revai.UserAgent("my-user-agent"),
)
Submit Local File Job
params := &revai.NewFileJobParams{
	Media:    f, // some io.Reader
	Filename: f.Name(),
}

ctx := context.Background()

job, err := c.Job.SubmitFile(ctx, params)
// handle err

fmt.Println("status", job.Status)
Submit Url Job
const mediaURL = "https://support.rev.com/hc/en-us/article_attachments/200043975/FTC_Sample_1_-_Single.mp3"

params := &revai.NewURLJobParams{
    MediaURL: mediaURL, 
}

ctx := context.Background()

job, err := c.Job.SubmitURL(ctx, params)
// handle err

fmt.Println("status", job.Status)
Caption
params := &revai.GetCaptionParams{
	JobID: "job-id"
}

ctx := context.Background()

caption, err := c.Caption.Get(ctx, params)
// error check

fmt.Println("srt caption", caption.Value)
Account
ctx := context.Background()

account, err := c.Account.Get(ctx)
// error check

fmt.Println("balance", account.BalanceSeconds)
Stream

streaming example

Documentation

Index

Constants

View Source
const (
	XSubripHeader           = "application/x-subrip"
	TextVTTHeader           = "text/vtt"
	TextPlainHeader         = "text/plain"
	RevTranscriptJSONHeader = "application/vnd.rev.transcript.v1.0+json"
)
View Source
const (
	StateConnected = iota
	StateDoneSent
	StateDone
)
View Source
const (
	ErrCloseUnauthorized        = 4001
	ErrCloseBadRequest          = 4002
	ErrCloseInsufficientCredits = 4003
	ErrCloseServerShuttingDown  = 4010
	ErrCloseNoInstanceAvailable = 4013
	ErrCloseTooManyRequests     = 4029
)

Error codes

Variables

This section is empty.

Functions

func BaseURL

func BaseURL(u *url.URL) func(*Client)

BaseURL sets the base url for the rev.ai client

func HTTPClient

func HTTPClient(httpClient *http.Client) func(*Client)

HTTPClient sets the http client for the rev.ai client

func IsRevError

func IsRevError(code int) (bool, error)

IsRevError Check if the code is a Rev error if so return it.

func UserAgent

func UserAgent(userAgent string) func(*Client)

UserAgent sets the user agent for the rev.ai client

Types

type Account

type Account struct {
	Email          string `json:"email"`
	BalanceSeconds int    `json:"balance_seconds"`
}

Account is the developer's account information

type AccountService

type AccountService service

AccountService provides access to the account related functions in the Rev.ai API.

func (*AccountService) Get

func (s *AccountService) Get(ctx context.Context) (*Account, error)

Get the developer's account information https://www.rev.ai/docs#operation/GetAccount

type Caption

type Caption struct {
	Value string
}

Caption output for a transcription job

type CaptionService

type CaptionService service

CaptionService provides access to the caption related functions in the Rev.ai API.

func (*CaptionService) Get

func (s *CaptionService) Get(ctx context.Context, params *GetCaptionParams) (*Caption, error)

Get returns the caption output for a transcription job. https://www.rev.ai/docs#tag/Captions

type Client

type Client struct {
	HTTPClient *http.Client
	BaseURL    *url.URL
	UserAgent  string

	APIKey string

	// Services used for talking to different parts of the Rev.ai API.
	Job              *JobService
	Account          *AccountService
	Caption          *CaptionService
	Transcript       *TranscriptService
	CustomVocabulary *CustomVocabularyService
	Stream           *StreamService
	// contains filtered or unexported fields
}

A Client manages communication with the Rev.ai API.

func NewClient

func NewClient(apiKey string, opts ...ClientOption) *Client

NewClient creates a new client and sets defaults. It then updates the client with any options passed in.

type ClientOption

type ClientOption func(*Client)

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn represents a websocket connection to the Rev.ai Api. It has certain helper methods to easily parse and communicate to the web socket connection

func (*Conn) Close

func (c *Conn) Close() error

Close closes the websocket connection

func (*Conn) Recv

func (c *Conn) Recv() (*StreamMessage, error)

Recv get messages back from rev

func (*Conn) Write

func (c *Conn) Write(r io.Reader) error

Write sends a message to the websocket connection

func (*Conn) WriteDone

func (c *Conn) WriteDone() error

WriteDone sends EOS to let Rev know we are done. see https://www.rev.ai/docs/streaming#section/Client-to-Rev.ai-Input/Sending-Audio-to-Rev.ai

type CreateCustomVocabularyParams

type CreateCustomVocabularyParams struct {
	CustomVocabularies []Phrase `json:"custom_vocabularies"`
	Metadata           string   `json:"metadata,omitempty"`
	CallbackURL        string   `json:"callback_url,omitempty"`
}

CreateCustomVocabularyParams specifies the parameters to the CustomVocabularyService.Create method.

type CustomVocabulary

type CustomVocabulary struct {
	ID            string    `json:"id"`
	Status        string    `json:"status"`
	CreatedOn     time.Time `json:"created_on"`
	CompletedOn   time.Time `json:"completed_on"`
	CallbackURL   string    `json:"callback_url"`
	Failure       string    `json:"failure"`
	FailureDetail string    `json:"failure_detail"`
}

CustomVocabulary represents a Rev.ai custom vocabulary

type CustomVocabularyService

type CustomVocabularyService service

CustomVocabularyService provides access to the custom vocabulary related functions in the Rev.ai API.

func (*CustomVocabularyService) Create

Create submits a Custom Vocabulary for asynchronous processing. https://www.rev.ai/docs/streaming#operation/SubmitCustomVocabulary

func (*CustomVocabularyService) Delete

Delete deletes the custom vocabulary. https://www.rev.ai/docs/streaming#operation/DeleteCustomVocabulary

func (*CustomVocabularyService) Get

Get gets the custom vocabulary processing information https://www.rev.ai/docs/streaming#operation/GetCustomVocabulary

func (*CustomVocabularyService) List

List gets a list of most recent custom vocabularies' processing information https://www.rev.ai/docs/streaming#operation/GetCustomVocabularies

type DeleteCustomVocabularyParams

type DeleteCustomVocabularyParams struct {
	ID string
}

DeleteCustomVocabularyParams specifies the parameters to the CustomVocabularyService.Delete method.

type DeleteJobParams

type DeleteJobParams struct {
	ID string
}

DeleteJobParams specifies the parameters to the JobService.Delete method.

type DialStreamParams

type DialStreamParams struct {
	ContentType        string
	Metadata           string
	FilterProfanity    bool
	RemoveDisfluencies bool
	CustomVocabularyID string
}

DialStreamParams specifies the parameters to the StreamService.Dial method.

type Element

type Element struct {
	Type       string  `json:"type"`
	Value      string  `json:"value"`
	Ts         float64 `json:"ts"`
	EndTs      float64 `json:"end_ts"`
	Confidence float64 `json:"confidence"`
}

Element represents a Rev.ai element

type ErrBadStatusCode

type ErrBadStatusCode struct {
	OriginalBody string
	Code         int
}

ErrBadStatusCode is returned when the API returns a non 2XX error code

func (*ErrBadStatusCode) Error

func (e *ErrBadStatusCode) Error() string

type GetCaptionParams

type GetCaptionParams struct {
	JobID  string
	Accept string
}

GetCaptionParams specifies the parameters to the CaptionService.Get method.

type GetCustomVocabularyParams

type GetCustomVocabularyParams struct {
	ID string
}

GetCustomVocabularyParams specifies the parameters to the CustomVocabularyService.Get method.

type GetJobParams

type GetJobParams struct {
	ID string
}

GetJobParams specifies the parameters to the JobService.Get method.

type GetTranscriptParams

type GetTranscriptParams struct {
	JobID string
}

GetTranscriptParams specifies the parameters to the TranscriptService.Get method.

type Job

type Job struct {
	ID               string    `json:"id"`
	CreatedOn        time.Time `json:"created_on"`
	Name             string    `json:"name"`
	Status           string    `json:"status"`
	Type             string    `json:"type"`
	Metadata         string    `json:"metadata,omitempty"`
	CompletedOn      time.Time `json:"completed_on,omitempty"`
	CallbackURL      string    `json:"callback_url,omitempty"`
	DurationSeconds  float32   `json:"duration_seconds,omitempty"`
	MediaURL         string    `json:"media_url,omitempty"`
	Failure          string    `json:"failure,omitempty"`
	FailureDetail    string    `json:"failure_detail,omitempty"`
	Language         string    `json:"language,omitempty"`
	DetectedLanguage string    `json:"detected_language,omitempty"`
}

Job represents a rev.ai async job.

type JobOptionCustomVocabulary

type JobOptionCustomVocabulary struct {
	Phrases []string `json:"phrases"`
}

type JobOptions

type JobOptions struct {
	SkipDiarization      bool                        `json:"skip_diarization,omitempty"`
	SkipPunctuation      bool                        `json:"skip_punctuation,omitempty"`
	RemoveDisfluencies   bool                        `json:"remove_disfluencies,omitempty"`
	FilterProfanity      bool                        `json:"filter_profanity,omitempty"`
	SpeakerChannelsCount int                         `json:"speaker_channels_count,omitempty"`
	Metadata             string                      `json:"metadata,omitempty"`
	CallbackURL          string                      `json:"callback_url,omitempty"`
	CustomVocabularies   []JobOptionCustomVocabulary `json:"custom_vocabularies,omitempty"`
	Transcriber          string                      `json:"transcriber,omitempty"`
	CustomVocabularyId   string                      `json:"custom_vocabulary_id,omitempty"`
	ForcedAlignment      bool                        `json:"forced_alignment,omitempty"`
	RemoveAtmospherics   bool                        `json:"remove_atmospherics,omitempty"`
	ApplyDurationPadding bool                        `json:"apply_duration_padding,omitempty"`
	EnableFusion         bool                        `json:"enable_fusion,omitempty"`
}

JobOptions specifies the options to the JobService.SubmitFile method.

type JobService

type JobService service

JobService provides access to the jobs related functions in the Rev.ai API.

func (*JobService) Delete

func (s *JobService) Delete(ctx context.Context, params *DeleteJobParams) error

Delete deletes a transcription job https://www.rev.ai/docs#operation/DeleteJobById

func (*JobService) Get

func (s *JobService) Get(ctx context.Context, params *GetJobParams) (*Job, error)

Get returns information about a transcription job https://www.rev.ai/docs#operation/GetJobById

func (*JobService) List

func (s *JobService) List(ctx context.Context, params *ListJobParams) ([]*Job, error)

List gets a list of transcription jobs submitted within the last 30 days in reverse chronological order up to the provided limit number of jobs per call. https://www.rev.ai/docs#operation/GetListOfJobs

func (*JobService) SubmitFile

func (s *JobService) SubmitFile(ctx context.Context, params *NewFileJobParams) (*Job, error)

SubmitFile starts an asynchronous job to transcribe speech-to-text for a media file. https://www.rev.ai/docs#operation/SubmitTranscriptionJob

func (*JobService) SubmitURL

func (s *JobService) SubmitURL(ctx context.Context, params *NewURLJobParams) (*Job, error)

SubmitURL starts an asynchronous job to transcribe speech-to-text for a media file. https://www.rev.ai/docs#operation/SubmitTranscriptionJob

type ListCustomVocabularyParams

type ListCustomVocabularyParams struct {
	Limit int `url:"limit,omitempty"`
}

ListCustomVocabularyParams specifies the parameters to the CustomVocabularyService.List method.

type ListJobParams

type ListJobParams struct {
	Limit         int    `url:"limit,omitempty"`
	StartingAfter string `url:"starting_after,omitempty"`
}

ListJobParams specifies the optional query parameters to the JobService.List method.

type Monologue

type Monologue struct {
	Speaker  int       `json:"speaker"`
	Elements []Element `json:"elements"`
}

Monologue represents a Rev.ai monologue

type NewFileJobParams

type NewFileJobParams struct {
	Media      io.Reader
	Filename   string
	JobOptions *JobOptions
}

NewFileJobParams specifies the parameters to the JobService.SubmitFile method.

type NewURLJobParams

type NewURLJobParams struct {
	MediaURL             string                      `json:"media_url"`
	SkipDiarization      bool                        `json:"skip_diarization,omitempty"`
	SkipPunctuation      bool                        `json:"skip_punctuation,omitempty"`
	RemoveDisfluencies   bool                        `json:"remove_disfluencies,omitempty"`
	FilterProfanity      bool                        `json:"filter_profanity,omitempty"`
	SpeakerChannelsCount int                         `json:"speaker_channels_count,omitempty"`
	Metadata             string                      `json:"metadata,omitempty"`
	CallbackURL          string                      `json:"callback_url,omitempty"`
	CustomVocabularies   []JobOptionCustomVocabulary `json:"custom_vocabularies"`
	Language             string                      `json:"language"`
	Transcriber          string                      `json:"transcriber,omitempty"`
	CustomVocabularyId   string                      `json:"custom_vocabulary_id,omitempty"`
	ForcedAlignment      bool                        `json:"forced_alignment,omitempty"`
	RemoveAtmospherics   bool                        `json:"remove_atmospherics,omitempty"`
	ApplyDurationPadding bool                        `json:"apply_duration_padding,omitempty"`
	EnableFusion         bool                        `json:"enable_fusion,omitempty"`
}

NewURLJobParams specifies the parameters to the JobService.SubmitURL method.

type Phrase

type Phrase struct {
	Phrases []string `json:"phrases"`
}

type RetriableError

type RetriableError struct {
	// Error code
	Code int

	// The error string
	Text string
}

RetriableError represnts retriable stream error

func (RetriableError) Error

func (e RetriableError) Error() string

type RevError

type RevError struct {
	// Error code
	Code int

	// The error string
	Text string
}

RevError represents a close message from rev see https://www.rev.ai/docs/streaming#section/Error-Codes

func (RevError) Error

func (e RevError) Error() string

type StreamMessage

type StreamMessage struct {
	Type     string    `json:"type"`
	Ts       float64   `json:"ts"`
	EndTs    float64   `json:"end_ts"`
	Elements []Element `json:"elements"`
}

StreamMessage represents a rev.ai websocket stream message.

type StreamService

type StreamService service

StreamService provides access to the stream related functions in the Rev.ai API.

func (*StreamService) Dial

func (s *StreamService) Dial(ctx context.Context, params *DialStreamParams) (*Conn, error)

Dial dials a WebSocket request to the Rev.ai Streaming api. https://www.rev.ai/docs/streaming#section/Overview

type TextTranscript

type TextTranscript struct {
	Value string
}

TextTranscript represents a Rev.ai job text transcript

type Transcript

type Transcript struct {
	Monologues []Monologue `json:"monologues"`
}

Transcript represents a Rev.ai job json transcript

type TranscriptService

type TranscriptService service

TranscriptService provides access to the transcript related functions in the Rev.ai API.

func (*TranscriptService) Get

Get returns the transcript for a completed transcription job in JSON format. https://www.rev.ai/docs#operation/GetTranscriptById

func (*TranscriptService) GetText

Get returns the transcript for a completed transcription job in text format. https://www.rev.ai/docs#operation/GetTranscriptById

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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