gotts

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 17 Imported by: 0

README

go-tts

Text To Speech:文字转语音

实现

golang + websocket

1. go mod tidy
2. cp tts.json config.json && edit 
3. go run main/tts.go

module

已实现 Bing/Azure TTS

Bing

    logger.Debug(gotts.Init("127.0.0.1:3030",
        gotts.WithWriter(&gotts.WriterFile{Path: os.Getenv("GOPATH")+"/src/gozny/log/tts/"}),
        gotts.WithVoice(gotts.YunyangNeural),
        gotts.WithToken("token"),
        gotts.WithModule(gotts.ConnModuleBing)))

Azure

    logger.Debug(gotts.Init("127.0.0.1:3030",
        gotts.WithWriter(&gotts.WriterFile{Path: os.Getenv("GOPATH")+"/src/gozny/log/tts/"}),
        gotts.WithVoice(gotts.YunyangNeural),
        gotts.WithToken("token"),
        gotts.WithModule(gotts.ConnModuleAzure)))

语音输出方式

可通过重定义接口 Writer方式实现多种语音输出方式

Documentation

Index

Constants

View Source
const (
	XiaoxiaoNeural   = "zh-CN-XiaoxiaoNeural"   // Xiaoxiao (Neural) - 晓晓	'general', 'assistant', 'chat', 'customerservice', 'newscast', 'affectionate', 'angry', 'calm', 'cheerful', 'disgruntled', 'fearful', 'gentle', 'lyrical', 'sad', 'serious'
	YunyangNeural    = "zh-CN-YunyangNeural"    // Yunyang (Neural) - 云扬	'general', 'customerservice', 'narration-professional', 'newscast-casual'
	XiaochenNeural   = "zh-CN-XiaochenNeural"   // Xiaochen (Neural) - 晓辰	'general'
	XiaohanNeural    = "zh-CN-XiaohanNeural"    // Xiaohan (Neural) - 晓涵	'general', 'calm', 'fearful', 'cheerful', 'disgruntled', 'serious', 'angry', 'sad', 'gentle', 'affectionate', 'embarrassed'
	XiaomoNeural     = "zh-CN-XiaomoNeural"     // Xiaomo (Neural) - 晓墨	'general', 'embarrassed', 'calm', 'fearful', 'cheerful', 'disgruntled', 'serious', 'angry', 'sad', 'depressed', 'affectionate', 'gentle', 'envious'
	XiaoqiuNeural    = "zh-CN-XiaoqiuNeural"    // Xiaoqiu (Neural) - 晓秋	'general'
	XiaoruiNeural    = "zh-CN-XiaoruiNeural"    // Xiaorui (Neural) - 晓睿	'general', 'calm', 'fearful', 'angry', 'sad'
	XiaoshuangNeural = "zh-CN-XiaoshuangNeural" // Xiaoshuang (Neural) - 晓双	'general', 'chat'
	XiaoxuanNeural   = "zh-CN-XiaoxuanNeural"   // Xiaoxuan (Neural) - 晓萱	'general', 'calm', 'fearful', 'cheerful', 'disgruntled', 'serious', 'angry', 'gentle', 'depressed'
	XiaoyanNeural    = "zh-CN-XiaoyanNeural"    // Xiaoyan (Neural) - 晓颜	'general'
	XiaoyouNeural    = "zh-CN-XiaoyouNeural"    // Xiaoyou (Neural) - 晓悠	'general'
	YunxiNeural      = "zh-CN-YunxiNeural"      // Yunxi (Neural) - 云希	'general', 'narration-relaxed', 'embarrassed', 'fearful', 'cheerful', 'disgruntled', 'serious', 'angry', 'sad', 'depressed', 'chat', 'assistant', 'newscast'
	YunyeNeural      = "zh-CN-YunyeNeural"      // Yunye (Neural) - 云野	'general', 'embarrassed', 'calm', 'fearful', 'cheerful', 'disgruntled', 'serious', 'angry', 'sad'
)

Variables

This section is empty.

Functions

func Fail

func Fail(w http.ResponseWriter, message string)

func GetUUID

func GetUUID() string

func GetXTime

func GetXTime() string

func Init

func Init(addr string, ops ...Options) error

func ReplaceText

func ReplaceText(text string) string

func Success

func Success(w http.ResponseWriter, data interface{})

Types

type Conn

type Conn struct {
	ID string
	*websocket.Conn
	// contains filtered or unexported fields
}

func (*Conn) GetID

func (c *Conn) GetID() string

type ConnAzure

type ConnAzure struct {
	Conn // Exceeded maximum websocket connection duration(> 1200000ms)
}

func (*ConnAzure) Heartbeat

func (c *ConnAzure) Heartbeat(s *Server)

func (*ConnAzure) Init

func (c *ConnAzure) Init(token string)

func (*ConnAzure) Read

func (c *ConnAzure) Read(s *Server)

func (*ConnAzure) Write

func (c *ConnAzure) Write(reqId, text, voice string) error

type ConnBing

type ConnBing struct {
	Conn
}

func (*ConnBing) Heartbeat

func (c *ConnBing) Heartbeat(s *Server)

func (*ConnBing) Init

func (c *ConnBing) Init(token string)

func (*ConnBing) Read

func (c *ConnBing) Read(s *Server)

func (*ConnBing) Write

func (c *ConnBing) Write(reqId, text, voice string) error

type ConnModule

type ConnModule string
const (
	ConnModuleAzure ConnModule = "azure"
	ConnModuleBing  ConnModule = "bing"
)

type IConn

type IConn interface {
	Read(s *Server)
	Write(reqId, text, voice string) error
	Init(token string)
	Heartbeat(s *Server)
	GetID() string
}

func GetConn

func GetConn(v interface{}, module ConnModule) IConn

func NewConn

func NewConn(module ConnModule) IConn

type Option

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

func GetOption

func GetOption(ops ...Options) *Option

type Options

type Options func(option *Option)

func WithModule

func WithModule(module ConnModule) Options

func WithToken

func WithToken(token string) Options

func WithVoice

func WithVoice(voice string) Options

func WithWriter

func WithWriter(w Writer) Options

type Resp

type Resp struct {
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

type Server

type Server struct {
	Conn sync.Map // websocket conn Exceeded maximum websocket connection duration
	// contains filtered or unexported fields
}

func (*Server) Start

func (s *Server) Start()

type StatResp

type StatResp struct {
	Success   int32  `json:"success"`
	Fail      int32  `json:"fail"`
	LastTime  string `json:"last_time"`
	ConnCount int    `json:"conn_count"`
}

type Writer

type Writer interface {
	Write(reqId string, body []byte) (string, error)
}

type WriterFile

type WriterFile struct {
	Path string
}

func (*WriterFile) Write

func (w *WriterFile) Write(reqId string, body []byte) (string, error)

type WriterQiniu

type WriterQiniu struct {
	Cfg  *qiniu.Config
	Path string
}

func (*WriterQiniu) Write

func (w *WriterQiniu) Write(reqId string, body []byte) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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