cybervox

package module
v0.0.0-...-8e89f3f Latest Latest
Warning

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

Go to latest
Published: May 11, 2021 License: MIT Imports: 8 Imported by: 0

README

About

This is an example client implementation written in GO to access the CyberVox platform API.

For more information, read the API documentation.

Getting Started

To run the example implementation:

export CLIENT_ID=< provided client id >
export CLIENT_SECRET=< provided client secret >

# complete API
go run cmd/example/main.go

# text-to-speech only
go run cmd/tts/main.go "olá mundo"

# speech-to-text only
go run cmd/stt/main.go ola-mundo.wav

Usage

GoDoc

go doc -all

Documentation

Overview

Package cybervox implements all structs and functions necessary to talk to the CyberVox api platform.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial() (*websocket.Conn, *http.Response, error)

Dial connects to the API's websocket. It assumes the env vars `CLIENT_ID` and `CLIENT_SECRET` are defined correctly. It returns the websocket.Conn, the http.Response and maybe an error.

Types

type PingRequest

type PingRequest struct {
	Emit    string             `json:"emit"`
	Payload PingRequestPayload `json:"payload"`
}

PingRequest contains the parameters to send a `ping` message to the platform.

type PingRequestPayload

type PingRequestPayload struct {
	Timestamp int64 `json:"timestamp"`
}

type PingResponse

type PingResponse struct {
	Event   string              `json:"event"`
	Payload PingResponsePayload `json:"payload"`
}

PingResponse contains the parameters sent in response to a `ping` message.

func Ping

func Ping(ws *websocket.Conn) (response PingResponse)

Ping sends a ping request on an established websocket connection. It receives the websocket.Conn and assumes it's properly connected and returns a PingResponse with the given Timestamp.

type PingResponsePayload

type PingResponsePayload struct {
	Success   bool  `json:"success"`
	Timestamp int64 `json:"timestamp,omitempty"` // the given PingRequestPayload.Timestamp
}

type STTRequest

type STTRequest struct {
	Emit    string            `json:"emit"`
	Payload STTRequestPayload `json:"payload"`
}

STTRequest contains the parameters to send a `stt` message to the platform.

type STTRequestPayload

type STTRequestPayload struct {
	Timestamp int64  `json:"timestamp"`
	UploadID  string `json:"upload_id"`
}

STTRequestPayload most important field is the `UploadID` to be transcribed into a text block.

type STTResponse

type STTResponse struct {
	Event   string             `json:"event"`
	Payload STTResponsePayload `json:"payload"`
}

STTResponse contains the parameters sent in response to a `stt` message.

func STT

func STT(ws *websocket.Conn, uploadID string) (response STTResponse)

STT sends a speech-to-text request on an established websocket connection. It receives the websocket.Conn and assumes it's properly connected and returns an STTResponse.

type STTResponsePayload

type STTResponsePayload struct {
	Success   bool   `json:"success"`   // successfully transcribed STTRequestPayload.UploadID into a block of text
	Reason    string `json:"reason"`    // if Success is false, the failure reason
	Text      string `json:"text"`      // if Success is true, the block of transcribed text
	Timestamp int64  `json:"timestamp"` // the given STTRequestPayload.Timestamp
}

type TTSRequest

type TTSRequest struct {
	Emit    string            `json:"emit"`
	Payload TTSRequestPayload `json:"payload"`
}

TTSRequest contains the parameters to send a `tts` message to the platform.

type TTSRequestPayload

type TTSRequestPayload struct {
	Timestamp int64  `json:"timestamp"`
	Text      string `json:"text"`
	Voice     string `json:"voice"`
}

TTSRequestPayload most important field is the `Text` to be converted into a WAVE file.

type TTSResponse

type TTSResponse struct {
	Event   string             `json:"event"`
	Payload TTSResponsePayload `json:"payload"`
}

TTSResponse contains the parameters sent in response to a `tts` message.

func TTS

func TTS(ws *websocket.Conn, text, voice string) (response TTSResponse)

TTS sends a text-to-speech request on an established websocket connection. It receives the websocket.Conn and assumes it's properly connected and returns a TTSResponse.

type TTSResponsePayload

type TTSResponsePayload struct {
	Success   bool   `json:"success"`             // successfully converted TTSRequestPayload.Text into a WAVE file
	Reason    string `json:"reason,omitempty"`    // if Success is false, the failure reason
	AudioURL  string `json:"audio_url,omitempty"` // if Success is true, the WAVE file url to be downloaded
	Timestamp int64  `json:"timestamp,omitempty"` // the given TTSRequestPayload.Timestamp
}

type UploadRequest

type UploadRequest struct {
	Emit    string               `json:"emit"`
	Payload UploadRequestPayload `json:"payload"`
}

UploadRequest contains the parameters to send a `upload` message to the platform.

type UploadRequestPayload

type UploadRequestPayload struct {
	Timestamp  int64 `json:"timestamp"`
	MaxUploads int   `json:"max_uploads"`
}

type UploadResponse

type UploadResponse struct {
	Event   string                `json:"event"`
	Payload UploadResponsePayload `json:"payload"`
}

UploadResponse contains the parameters sent in response to an `upload` message.

func Upload

func Upload(ws *websocket.Conn, filename string) (response UploadResponse)

Upload sends an upload request followed by a bytes stream on an established websocket connection. It receives the websocket.Conn and assumes it's properly connected and returns an UploadResponse.

type UploadResponsePayload

type UploadResponsePayload struct {
	UploadID  string `json:"upload_id"` // the generated uuid valid for some time
	Timestamp int64  `json:"timestamp"` // the given UploadRequestPayload.Timestamp
}

Directories

Path Synopsis
cmd
stt
tts

Jump to

Keyboard shortcuts

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