Skip to content

chicogong/flow-tts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

FlowTTS

Node.js CI Python CI Go CI License: MIT

OpenAI-style TTS SDK for Tencent Cloud - Simple, elegant, multi-language

English | ็ฎ€ไฝ“ไธญๆ–‡

FlowTTS is a lightweight Text-to-Speech SDK that wraps Tencent Cloud's TRTC TTS API with an OpenAI-compatible interface. Available in Node.js, Python, Go, and Java.

๐ŸŽฎ Try it Now

Experience FlowTTS instantly without any setup:

Platform Link Description
Hugging Face gonghaoran/flow-tts Free Gradio demo
Streamlit flowtts.streamlit.app Interactive demo
Replicate chicogong/flow-tts API + Playground

BYOK (Bring Your Own Key): You need your own Tencent Cloud credentials to use these demos. See flowtts-byok for deployment guides.

โœจ Features

  • ๐ŸŽฏ OpenAI-Compatible API - Drop-in replacement for OpenAI TTS
  • ๐ŸŒ Multi-Language SDKs - Node.js, Python, and Go implementations
  • โšก Zero Dependencies - Uses only built-in libraries
  • ๐Ÿ”ท Type-Safe - Full TypeScript, Python type hints, and Go static typing
  • ๐ŸŒŠ Streaming Support - Real-time audio streaming
  • ๐ŸŽค Rich Voice Library - 380+ preset voices in multiple languages
  • ๐Ÿ” Auto Language Detection - Automatically detects text language

๐Ÿ“ฆ Installation

Node.js

npm install flow-tts

Python

pip install flow-tts

Go

go get github.com/chicogong/flow-tts/go

๐Ÿš€ Quick Start

Node.js

import { FlowTTS } from 'flow-tts';

const client = new FlowTTS({
  secretId: process.env.TX_SECRET_ID!,
  secretKey: process.env.TX_SECRET_KEY!,
  sdkAppId: parseInt(process.env.TRTC_SDK_APP_ID!)
});

// OpenAI-compatible API
const response = await client.audio.speech.create({
  text: 'Hello, world!',
  voice: 'v-female-R2s4N9qJ'
});

await fs.writeFile('output.wav', response.audio);

Python

from flow_tts import FlowTTS

client = FlowTTS({
    "secret_id": "your-secret-id",
    "secret_key": "your-secret-key",
    "sdk_app_id": 1400000000
})

# Synthesize speech
response = client.synthesize({
    "text": "ไฝ ๅฅฝ๏ผŒไธ–็•Œ๏ผ",
    "voice": "v-female-R2s4N9qJ",
    "format": "wav"
})

# Save to file
with open("output.wav", "wb") as f:
    f.write(response["audio"])

Go

package main

import (
    "os"
    flowtts "github.com/chicogong/flow-tts/go"
)

func main() {
    client, _ := flowtts.NewClient(flowtts.Config{
        SecretID:  os.Getenv("TX_SECRET_ID"),
        SecretKey: os.Getenv("TX_SECRET_KEY"),
        SdkAppID:  1400000000,
    })

    response, _ := client.Synthesize(flowtts.SynthesizeOptions{
        Text:   "ไฝ ๅฅฝ๏ผŒไธ–็•Œ๏ผ",
        Voice:  "v-female-R2s4N9qJ",
        Format: flowtts.AudioFormatWAV,
    })

    os.WriteFile("output.wav", response.Audio, 0644)
}

๐Ÿ“š Documentation

๐ŸŽค Voice Library

The SDK provides 380+ preset voices:

  • 77 Turbo voices (low latency)
  • 303 Extended voices (high quality)

Recommended Voices

Voice ID Name Language Features
v-female-R2s4N9qJ ๆธฉๆŸ”ๅงๅง Chinese Gentle, Warm
v-male-Bk7vD3xP ๅจไธฅ้œธๆ€ป Chinese Mature, Steady
v-female-p9Xy7Q1L ๆธ…ๆ™ฐๅฅณๆ—็™ฝ English Clear, Professional

๐ŸŒŠ Streaming Support

All SDKs support real-time streaming:

Node.js:

for await (const chunk of client.synthesizeStream({ text: '...' })) {
  if (chunk.type === 'audio') {
    console.log(`Received ${chunk.data.length} bytes`);
  }
}

Python:

for chunk in client.synthesize_stream({"text": "..."}):
    if chunk["type"] == "audio":
        print(f"Received {len(chunk['data'])} bytes")

Go:

chunkChan, _ := client.SynthesizeStream(flowtts.SynthesizeOptions{Text: "..."})
for chunk := range chunkChan {
    if chunk.Type == "audio" {
        fmt.Printf("Received %d bytes\n", len(chunk.Data))
    }
}

โš™๏ธ Configuration

All SDKs require the same credentials:

TX_SECRET_ID=your-tencent-cloud-secret-id
TX_SECRET_KEY=your-tencent-cloud-secret-key
TRTC_SDK_APP_ID=your-trtc-app-id

๐Ÿ”ง Development

# Install dependencies (Node.js)
pnpm install

# Build Node.js SDK
pnpm --filter flow-tts build

# Test Python SDK
cd packages/python && pytest

# Test Go SDK
cd packages/go && go test ./...

๐Ÿ“Š SDK Comparison

Feature Node.js Python Go
Zero Dependencies โœ… โœ… โœ…
Type Safety TypeScript Type Hints Static Types
Streaming โœ… โœ… โœ…
Voice Library 380+ 380+ 380+
OpenAI Compatible โœ… โœ… โœ…
Package Manager npm PyPI go get

๐Ÿ“„ License

MIT License - see LICENSE file

๐Ÿค Contributing

Issues and Pull Requests are welcome!

๐Ÿ“ฎ Links

๐Ÿ™ Acknowledgments

Built on top of Tencent Cloud TRTC TTS API.