voicetext

package module
v0.0.0-...-801caf5 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2018 License: MIT Imports: 7 Imported by: 1

README

go-voicetext - VoiceText Web API クライアント

wercker status Coverage Status GoDoc

概要

go-voicetextはGo言語向けのVoiceText Web APIクライアントです。

インストール

go get -u github.com/yosssi/go-voicetext

実装例

go-voicetextを用いた簡単な実装例を以下に記載します。

package main

import (
	"fmt"
	"os"

	"github.com/yosssi/go-voicetext"
)

func main() {
	c := voicetext.NewClient(os.Getenv("VOICETEXT_API_KEY"), nil)
	result, err := c.TTS("Hello.", nil)
	if err != nil {
		panic(err)
	}

	if result.ErrMsg != nil {
		fmt.Println(result.ErrMsg)
		return
	}

	f, err := os.Create("hello.wav")
	if err != nil {
		panic(err)
	}

	defer func() {
		if err := f.Close(); err != nil {
			panic(err)
		}
	}()

	if _, err := f.Write(result.Sound); err != nil {
		panic(err)
	}
}

以下のように、TTSメソッドにオプションの設定を指定することができます。

package main

import (
	"fmt"
	"os"

	"github.com/yosssi/go-voicetext"
)

func main() {
	c := voicetext.NewClient(os.Getenv("VOICETEXT_API_KEY"), nil)
	result, err := c.TTS("Hello.", &voicetext.TTSOptions{
		Speaker:      voicetext.SpeakerHaruka,
		Emotion:      voicetext.EmotionHappiness,
		EmotionLevel: "2",
		Pitch:        90,
		Speed:        110,
		Volume:       200,
	})
	if err != nil {
		panic(err)
	}

	if result.ErrMsg != nil {
		fmt.Println(result.ErrMsg)
		return
	}

	f, err := os.Create("hello.wav")
	if err != nil {
		panic(err)
	}

	defer func() {
		if err := f.Close(); err != nil {
			panic(err)
		}
	}()

	if _, err := f.Write(result.Sound); err != nil {
		panic(err)
	}
}

ドキュメント

Documentation

Overview

Package voicetext provides a VoiceText Web API client.

Index

Constants

View Source
const (
	EmotionHappiness = "happiness"
	EmotionAnger     = "anger"
	EmotionSadness   = "sadness"
)

Emotions

Variables

View Source
var (
	SpeakerShow = speaker{
				// contains filtered or unexported fields
	}
	SpeakerHaruka = speaker{
					// contains filtered or unexported fields
	}
	SpeakerHikari = speaker{
					// contains filtered or unexported fields
	}
	SpeakerTakeru = speaker{
					// contains filtered or unexported fields
	}
	SpeakerSanta = speaker{
					// contains filtered or unexported fields
	}
	SpeakerBear = speaker{
				// contains filtered or unexported fields
	}
)

Speakers

Functions

func NewClient

func NewClient(apiKey string, opts *ClientOptions) *client

NewClient creates and

Types

type Client

type Client interface {
	// TTS calls the tts API.
	TTS(text string, opts *TTSOptions) (*Result, error)
}

Client is an interface for calling VoiceText Web API.

type ClientOptions

type ClientOptions struct {
	// Version represents the version of VoiceText Web API.
	Version string
}

ClientOptions represents options for a client.

type ErrMsg

type ErrMsg interface {
	String() string
}

ErrMsg is an interface for printing an error message returned by the API.

type Result

type Result struct {
	// Status represents an HTTP status.
	Status int
	// Sound represents a sound data.
	Sound []byte
	// ErrMsg represents an error message.
	ErrMsg ErrMsg
}

Result represents a result of the API call.

type TTSErrMsg

type TTSErrMsg struct {
	Err TTSErrMsgError `json:"error"`
}

TTSErrMsg represents an error meesage of the TTS method.

func (*TTSErrMsg) String

func (msg *TTSErrMsg) String() string

String returns the error message.

type TTSErrMsgError

type TTSErrMsgError struct {
	Message string `json:"message"`
}

TTSErrMsgError represents an error of the tts error message.

type TTSOptions

type TTSOptions struct {
	// Speaker represents a speaker of the speech.
	Speaker speaker
	// Emotion represents an emotion of the speech.
	Emotion string
	// EmotionLevel represents an emotion level of the speech.
	EmotionLevel string
	// Pitch represents a pitch of the speech.
	Pitch int
	// Speed represents a speed of the speech.
	Speed int
	// Volume represents a volume of the speech.
	Volume int
}

TTSOptions represents options for the TTS method.

Jump to

Keyboard shortcuts

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