Skip to content

murchinroom/sayerapigo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

muli::SayerApiGo

sayerapigo is a muli component that provides Sayer (Text-to-Speech) Service & Client API implementation in Go.

🔑 This is a muli component. You can find the main repository here.

⚠️ Following documentation is generated by ChatGPT. It may not be accurate.

Installation

Use go get to install SayerApiGo.

go get github.com/murchinroom/sayerapigo

Usage

Interface

The Sayer interface defines the Say method, which takes in a role and text, and returns the format of the audio file and the audio file content.

type Sayer interface {
	Say(role string, text string) (format string, audio []byte, err error)
}

Server

The ServeGrpc function serves the gRPC server for the SayerService. You need to provide a Sayer implementation that will be used to handle incoming requests.

func ServeGrpc(ctx context.Context, sayer Sayer, addr string) error

An example of how to use the ServeGrpc function can be found in the Examples section.

Client

The SayerClient struct is a gRPC client for the SayerService. You can use it to make text-to-speech conversion requests.

type SayerClient struct {
    // ...
}

func NewSayerClient(addr string) (*SayerClient, error)

func (c *SayerClient) Say(role string, text string) (format string, audio []byte, err error)

func (c *SayerClient) Close() error

There is also a SayerClientPool struct, which is a pool of SayerClients. It implements the Sayer interface, so you can use it as a Sayer.

type SayerClientPool struct {
    // ...
}

func NewSayerClientPool(addr string, size int64) (*SayerClientPool, error)

func (p *SayerClientPool) Say(role string, text string) (format string, audio []byte, err error)

Examples

Here's an example of how to use the SayerApiGo library:

package main

import (
	"context"
	"fmt"

	"github.com/murchinroom/sayerapigo"
)

type MySayer struct {}

func (s *MySayer) Say(role string, text string) (format string, audio []byte, err error) {
    // Your text-to-speech conversion code here
}

func main() {
    // Create a new MySayer instance
    sayer := &MySayer{}

    // Serve the gRPC server
    ctx := context.Background()
    err := sayerapigo.ServeGrpc(ctx, sayer, "localhost:9000")
    if err != nil {
        fmt.Printf("Error serving gRPC server: %v\n", err)
        return
    }

    // Create a new SayerClient
    client, err := sayerapigo.NewSayerClient("localhost:9000")
    if err != nil {
        fmt.Printf("Error creating SayerClient: %v\n", err)
        return
    }
    defer client.Close()

    // Call the Say method to convert text to speech
    format, audio, err := client.Say("default", "Hello, World!")
    if err != nil {
        fmt.Printf("Error converting text to speech: %v\n", err)
        return
    }

    // Do something with the audio file
    fmt.Printf("Audio file format: %v\n", format)
    fmt.Printf("Audio file content: %v\n", audio)
}

License

SayerApiGo is licensed under the MIT license. See the LICENSE file for more information.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages