papago

package module
v0.0.0-...-9416a00 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2021 License: Apache-2.0 Imports: 6 Imported by: 1

README

Naver Papago Translate - unofficial

official website

A simple wrapper around the web interface of Naver Papago Translate written in Go.

Installation

go get -u github.com/arrufat/papago

Features

Currently, this wrapper supports the following features:

  1. Translation in all supported languages.
  2. Automatic language detection.
  3. Text to Speech generation for a given text.

See the examples directory to see its usage.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TTS

func TTS(text string, voice Voice) (string, error)

TTS generates a URL to the MP3 file containing the sound

func Translate

func Translate(text string, source Language, target Language, opt TranslateOptions) (string, error)

Translate translates the text from source Language to target Language

Types

type Dict

type Dict struct {
	Items []DictItem
}

Dict structure in a TranslateResponse

type DictItem

type DictItem struct {
	Entry         string
	SubEntry      string
	MatchType     string
	HanjaEntry    string
	PhoneticSigns []PhoneticSign
	Pos           []ItemPos
	Source        string
	URL           string
	MURL          string
}

DictItem is an entry in a Dict structure

type Gender

type Gender int32

Gender used for the TTS

const (
	Male Gender = iota
	Female
)

Possible values for Gender

func (Gender) String

func (gender Gender) String() string

type ItemPos

type ItemPos struct {
	Type string
}

ItemPos describes the item pos in a DictItem

type Language

type Language int32

Language defines supported languages by Papago

const (
	Korean Language = iota
	English
	Japanese
	Chinese
	TraditionalChinese
	Spanish
	French
	German
	Russian
	Portuguese
	Italian
	Vietnamese
	Thai
	Indonesian
	Hindi
)

Languages supported by Papago

func Detect

func Detect(text string) (Language, error)

Detect tries to guess the input language from the given text

func ParseLanguageCode

func ParseLanguageCode(code string) (Language, error)

ParseLanguageCode returns the corresponding Language for a given code

func SupportedLanguages

func SupportedLanguages() []Language

SupportedLanguages returns the languages supported by Papago

func (Language) Code

func (lang Language) Code() string

Code returns the language code

func (Language) FemaleVoice

func (lang Language) FemaleVoice() string

FemaleVoice returns the name of the female voice for that Language

func (Language) MaleVoice

func (lang Language) MaleVoice() string

MaleVoice returns the name of the female voice for that Language

func (Language) String

func (lang Language) String() string

String prints the canonical Language name

type PhoneticSign

type PhoneticSign struct {
	Type string
	Sign string
}

PhoneticSign describes the phonetic sign in a DictItem

type Pitch

type Pitch int32

Pitch sets the TTS voice pitch

const (
	Lowest Pitch = iota - 5
	SuperLow
	VeryLow
	Low
	MidLow
	Medium
	MidHigh
	High
	VeryHigh
	SuperHigh
	Highest
)

Possible values for Pitch

type PosMeaning

type PosMeaning struct {
	Meaning string
}

PosMeaning describes the pos meaning in a DictItem

type Speed

type Speed int32

Speed controls the TTS speed

const (
	VerySlow Speed = iota
	Slow
	Normal
	Fast
)

Possible values for TTS speed

func (Speed) String

func (speed Speed) String() string

type TranslateOptions

type TranslateOptions struct {
	// Dict controls wether to request the dictionary
	Dict bool
	// DictDisplay sets the maximum amount of entries in the dictionary
	DictDisplay int
	// Instant requests instant translation
	Instant bool
	// Paging request
	Paging bool
	// Source is the language code for the source language
	Source string
	// Target is the language code for the target language
	Target string
	// Honorific requests honorific translation (from en to ko only)
	Honorific bool
	// Text is the string to be translated from the source to the target language
	Text string
}

TranslateOptions defines the options for the Translate function

func (TranslateOptions) String

func (opt TranslateOptions) String() string

type TranslateResponse

type TranslateResponse struct {
	SrcLangType    string
	TarLangType    string
	TranslatedText string
	Dict           Dict
	TarDict        Dict
	Delay          int
	DelaySmt       int
}

TranslateResponse contains the structure of a translate response

type Voice

type Voice struct {
	Language Language
	Gender   Gender
	Speed    Speed
	Pitch    Pitch
}

Voice contains the parameters for text to speech generation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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