azuretexttospeech

package module
v0.0.0-...-b1719e0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 14 Imported by: 0

README

AzureTextToSpeech Client

Execute Test Cases

This package provides a client for Azure's Cognitive Services (speech services) Text To Speech API. Users of the client can specify the lanaguage (Region type), a string containing the desired text to speak as well as the gender (Gender type) in which the audiofile should be rendered. The library fetches the audio rendered in the format of your choice (see AudioOutput types for supported formats).

API documents of interest

Requirements

A Cognitive Services (kind=Speech Services) API key is required to access the URL. This service can be enabled at the Azure portal.

Howto

The following will synthesize the string 64 BASIC BYTES FREE. READY., using the en-US locale, rending with a female voice. The output file format is a 16khz 32kbit single channel MP3 audio file.

import tts "github.com/jesseward/azuretexttospeech"
func main() {
    # See TextToSpeechAPI and TokenRefreshAPI types for list of endpoints and regions.
    azureSpeech, _ := tts.New("YOUR-API-KEY", tts.RegionEastUS)
    ctx := context.Background()
    payload, _ := az.SynthesizeWithContext(
        ctx,
        "64 BASIC BYTES FREE. READY.",
        tts.LocaleEnUS,                  // Region type
        tts.GenderFemale,                // Gender type
        tts.Audio16khz32kbitrateMonoMp3) // AudioOutput type
    // the response `payload` is your byte array containing audio data.
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MapAudioFileExtensions = map[string]string{
	"RAW16khz16bitMonoPCM":         "raw",
	"RAW24khz16bitMonoPCM":         "raw",
	"RAW48khz16bitMonoPCM":         "raw",
	"RAW8khz8bitMonoMulaw":         "raw",
	"RAW8khz8bitMonoAlaw":          "raw",
	"AUDIO16khz32kbitrateMonoMP3":  "mp3",
	"AUDIO16khz128kbitrateMonoMP3": "mp3",
	"AUDIO24khz96kbitrateMonoMP3":  "mp3",
	"AUDIO48khz96kbitrateMonoMP3":  "mp3",
	"RAW16khz16bitMonoTruesilk":    "raw",
	"WEBM16khz16bitMonoOpus":       "opus",
	"OGG16khz16bitMonoOpus":        "opus",
	"OGG48khz16bitMonoOpus":        "opus",
	"RIFF16khz16bitMonoPCM":        "wav",
	"RIFF24khz16bitMonoPCM":        "wav",
	"RIFF48khz16bitMonoPCM":        "wav",
	"RIFF8khz8bitMonoMulaw":        "wav",
	"RIFF8khz8bitMonoAlaw":         "wav",
	"AUDIO16khz64kbitrateMonoMP3":  "mp3",
	"AUDIO24khz48kbitrateMonoMP3":  "mp3",
	"AUDIO24khz160kbitrateMonoMP3": "mp3",
	"AUDIO48khz192kbitrateMonoMP3": "mp3",
	"RAW24khz16bitMonoTruesilk":    "raw",
	"WEBM24khz16bitMonoOpus":       "webm",
	"OGG24khz16bitMonoOpus":        "ogg",
}
View Source
var MapAudioToFormatid = map[string]AudioOutput{
	"RAW16khz16bitMonoPCM":         RAW16khz16bitMonoPCM,
	"RAW24khz16bitMonoPCM":         RAW24khz16bitMonoPCM,
	"RAW48khz16bitMonoPCM":         RAW48khz16bitMonoPCM,
	"RAW8khz8bitMonoMulaw":         RAW8khz8bitMonoMulaw,
	"RAW8khz8bitMonoAlaw":          RAW8khz8bitMonoAlaw,
	"AUDIO16khz32kbitrateMonoMP3":  AUDIO16khz32kbitrateMonoMP3,
	"AUDIO16khz128kbitrateMonoMP3": AUDIO16khz128kbitrateMonoMP3,
	"AUDIO24khz96kbitrateMonoMP3":  AUDIO24khz96kbitrateMonoMP3,
	"AUDIO48khz96kbitrateMonoMP3":  AUDIO48khz96kbitrateMonoMP3,
	"RAW16khz16bitMonoTruesilk":    RAW16khz16bitMonoTruesilk,
	"WEBM16khz16bitMonoOpus":       WEBM16khz16bitMonoOpus,
	"OGG16khz16bitMonoOpus":        OGG16khz16bitMonoOpus,
	"OGG48khz16bitMonoOpus":        OGG48khz16bitMonoOpus,
	"RIFF16khz16bitMonoPCM":        RIFF16khz16bitMonoPCM,
	"RIFF24khz16bitMonoPCM":        RIFF24khz16bitMonoPCM,
	"RIFF48khz16bitMonoPCM":        RIFF48khz16bitMonoPCM,
	"RIFF8khz8bitMonoMulaw":        RIFF8khz8bitMonoMulaw,
	"RIFF8khz8bitMonoAlaw":         RIFF8khz8bitMonoAlaw,
	"AUDIO16khz64kbitrateMonoMP3":  AUDIO16khz64kbitrateMonoMP3,
	"AUDIO24khz48kbitrateMonoMP3":  AUDIO24khz48kbitrateMonoMP3,
	"AUDIO24khz160kbitrateMonoMP3": AUDIO24khz160kbitrateMonoMP3,
	"AUDIO48khz192kbitrateMonoMP3": AUDIO48khz192kbitrateMonoMP3,
	"RAW24khz16bitMonoTruesilk":    RAW24khz16bitMonoTruesilk,
	"WEBM24khz16bitMonoOpus":       WEBM24khz16bitMonoOpus,
	"OGG24khz16bitMonoOpus":        OGG24khz16bitMonoOpus,
}

Functions

func GenderStrings

func GenderStrings() []string

GenderStrings returns a slice of all String values of the enum

func LocaleStrings

func LocaleStrings() []string

LocaleStrings returns a slice of all String values of the enum

Types

type AudioOutput

type AudioOutput int
const (
	RAW16khz16bitMonoPCM AudioOutput = iota
	RAW24khz16bitMonoPCM
	RAW48khz16bitMonoPCM
	RAW8khz8bitMonoMulaw
	RAW8khz8bitMonoAlaw
	AUDIO16khz32kbitrateMonoMP3
	AUDIO16khz128kbitrateMonoMP3
	AUDIO24khz96kbitrateMonoMP3
	AUDIO48khz96kbitrateMonoMP3
	RAW16khz16bitMonoTruesilk
	WEBM16khz16bitMonoOpus
	OGG16khz16bitMonoOpus
	OGG48khz16bitMonoOpus
	RIFF16khz16bitMonoPCM
	RIFF24khz16bitMonoPCM
	RIFF48khz16bitMonoPCM
	RIFF8khz8bitMonoMulaw
	RIFF8khz8bitMonoAlaw
	AUDIO16khz64kbitrateMonoMP3
	AUDIO24khz48kbitrateMonoMP3
	AUDIO24khz160kbitrateMonoMP3
	AUDIO48khz192kbitrateMonoMP3
	RAW24khz16bitMonoTruesilk
	WEBM24khz16bitMonoOpus
	OGG24khz16bitMonoOpus
)

func (AudioOutput) String

func (a AudioOutput) String() string

type AzureCSTextToSpeech

type AzureCSTextToSpeech struct {
	RegionVoiceMap     RegionVoiceMap
	SubscriptionKey    string    // API key for Azure's Congnitive Speech services
	TokenRefreshDoneCh chan bool // channel to stop the token refresh goroutine.

	HttpProxy string
	// contains filtered or unexported fields
}

AzureCSTextToSpeech stores configuration and state information for the TTS client.

func New

func New(subscriptionKey string, region Region, proxy string) (*AzureCSTextToSpeech, error)

New returns an AzureCSTextToSpeech object.

func (*AzureCSTextToSpeech) Synthesize

func (az *AzureCSTextToSpeech) Synthesize(speechText string, locale Locale, name, pitch, rate string, audioOutput AudioOutput) ([]byte, error)

Synthesize directs to SynthesizeWithContext. A new context.Withtimeout is created with the timeout as defined by synthesizeActionTimeout

func (*AzureCSTextToSpeech) SynthesizeWithContext

func (az *AzureCSTextToSpeech) SynthesizeWithContext(ctx context.Context, speechText string, locale Locale, name, pitch, rate string, audioOutput AudioOutput) ([]byte, error)

SynthesizeWithContext returns a bytestream of the rendered text-to-speech in the target audio format. `speechText` is the string of text in which a user wishes to Synthesize, `region` is the language/locale, `gender` is the desired output voice and `audioOutput` captures the audio format.

type ExtendedPropertyMap

type ExtendedPropertyMap struct {
	IsHighQuality48K string `json:"IsHighQuality48K,omitempty"`
}

type Gender

type Gender int

Gender type for the digitized language

const (
	// GenderMale , GenderFemale are the static Gender constants for digitized voices.
	// See Gender in https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support#standard-voices for breakdown
	GenderMale   Gender = iota // Male
	GenderFemale               // Female
)

func GenderString

func GenderString(s string) (Gender, error)

GenderString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func GenderValues

func GenderValues() []Gender

GenderValues returns all values of the enum

func (Gender) IsAGender

func (i Gender) IsAGender() bool

IsAGender returns "true" if the value is listed in the enum definition. "false" otherwise

func (Gender) MarshalJSON

func (i Gender) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Gender

func (Gender) String

func (i Gender) String() string

func (*Gender) UnmarshalJSON

func (i *Gender) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Gender

type Locale

type Locale int

Locale references the language or locale for text-to-speech. See "locale" in https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support#standard-voices

const (
	LocaleafZA  Locale = iota //af-ZA
	LocaleamET                //am-ET
	LocalearAE                //ar-AE
	LocalearBH                //ar-BH
	LocalearDZ                //ar-DZ
	LocalearEG                //ar-EG
	LocalearIQ                //ar-IQ
	LocalearJO                //ar-JO
	LocalearKW                //ar-KW
	LocalearLY                //ar-LY
	LocalearMA                //ar-MA
	LocalearQA                //ar-QA
	LocalearSA                //ar-SA
	LocalearSY                //ar-SY
	LocalearTN                //ar-TN
	LocalearYE                //ar-YE
	LocalebgBG                //bg-BG
	LocalebnBD                //bn-BD
	LocalecaES                //ca-ES
	LocalecsCZ                //cs-CZ
	LocalecyGB                //cy-GB
	LocaledaDK                //da-DK
	LocaledeAT                //de-AT
	LocaledeCH                // de-CH
	LocaledeDE                // de-DE
	LocaleelGR                // el-GR
	LocaleenAU                // en-AU
	LocaleenCA                // en-CA
	LocaleenGB                // en-GB
	LocaleenHK                // en-HK
	LocaleenIE                // en-IE
	LocaleenIN                // en-IN
	LocaleenKE                // en-KE
	LocaleenNG                // en-NG
	LocaleenNZ                // en-NZ
	LocaleenPH                // en-PH
	LocaleenSG                // en-SG
	LocaleenTZ                // en-TZ
	LocaleenUS                // en-US
	LocaleenZA                // en-ZA
	LocaleesAR                // es-AR
	LocaleesBO                // es-BO
	LocaleesCL                // es-CL
	LocaleesCO                // es-CO
	LocaleesCR                // es-CR
	LocaleesCU                // es-CU
	LocaleesDO                // es-DO
	LocaleesEC                // es-EC
	LocaleesES                // es-ES
	LocaleesGQ                // es-GQ
	LocaleesGT                // es-GT
	LocaleesHN                // es-HN
	LocaleesMX                // es-MX
	LocaleesNI                // es-NI
	LocaleesPA                // es-PA
	LocaleesPE                // es-PE
	LocaleesPR                // es-PR
	LocaleesPY                // es-PY
	LocaleesSV                // es-SV
	LocaleesUS                // es-US
	LocaleesUY                // es-UY
	LocaleesVE                // es-VE
	LocaleetEE                // et-EE
	LocalefaIR                // fa-IR
	LocalefiFI                // fi-FI
	LocalefilPH               // fil-PH
	LocalefrBE                // fr-BE
	LocalefrCA                // fr-CA
	LocalefrCH                // fr-CH
	LocalefrFR                // fr-FR
	LocalegaIE                // ga-IE
	LocaleglES                // gl-ES
	LocaleguIN                // gu-IN
	LocaleheIL                // he-IL
	LocalehiIN                // hi-IN
	LocalehrHR                // hr-HR
	LocalehuHU                // hu-HU
	LocaleidID                // id-ID
	LocaleitIT                // it-IT
	LocalejaJP                // ja-JP
	LocalejvID                // jv-ID
	LocalekmKH                // km-KH
	LocalekoKR                // ko-KR
	LocaleltLT                // lt-LT
	LocalelvLV                // lv-LV
	LocalemrIN                // mr-IN
	LocalemsMY                // ms-MY
	LocalemtMT                // mt-MT
	LocalemyMM                // my-MM
	LocalenbNO                // nb-NO
	LocalenlBE                // nl-BE
	LocalenlNL                // nl-NL
	LocaleplPL                // pl-PL
	LocaleptBR                // pt-BR
	LocaleptPT                // pt-PT
	LocaleroRO                // ro-RO
	LocaleruRU                // ru-RU
	LocaleskSK                // sk-SK
	LocaleslSI                // sl-SI
	LocalesoSO                // so-SO
	LocalesuID                // su-ID
	LocalesvSE                // sv-SE
	LocaleswKE                // sw-KE
	LocaleswTZ                // sw-TZ
	LocaletaIN                // ta-IN
	LocaletaLK                // ta-LK
	LocaletaSG                // ta-SG
	LocaleteIN                // te-IN
	LocalethTH                // th-TH
	LocaletrTR                // tr-TR
	LocaleukUA                // uk-UA
	LocaleurIN                // ur-IN
	LocaleurPK                // ur-PK
	LocaleuzUZ                // uz-UZ
	LocaleviVN                // vi-VN
	LocalezhCN                // zh-CN
	LocalezhHK                // zh-HK
	LocalezhTW                // zh-TW
	LocalezuZA                // zu-ZA
)

func LocaleString

func LocaleString(s string) (Locale, error)

LocaleString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func LocaleValues

func LocaleValues() []Locale

LocaleValues returns all values of the enum

func (Locale) IsALocale

func (i Locale) IsALocale() bool

IsALocale returns "true" if the value is listed in the enum definition. "false" otherwise

func (Locale) MarshalJSON

func (i Locale) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Locale

func (Locale) String

func (i Locale) String() string

func (*Locale) UnmarshalJSON

func (i *Locale) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Locale

type Region

type Region int

Region references the locations of the availability of standard voices. See https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/regions#standard-voices

const (
	// Azure regions and their endpoints that support the Text To Speech service.
	RegionAustraliaEast Region = iota
	RegionBrazilSouth
	RegionCanadaCentral
	RegionCentralUS
	RegionEastAsia
	RegionEastUS
	RegionEastUS2
	RegionFranceCentral
	RegionIndiaCentral
	RegionJapanEast
	RegionJapanWest
	RegionKoreaCentral
	RegionNorthCentralUS
	RegionNorthEurope
	RegionSouthCentralUS
	RegionSoutheastAsia
	RegionUKSouth
	RegionWestEurope
	RegionWestUS
	RegionWestUS2
)

func (Region) String

func (t Region) String() string

type RegionVoiceMap

type RegionVoiceMap map[supportedVoices]string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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