Skip to content

Latest commit

 

History

History
235 lines (172 loc) · 6.18 KB

File metadata and controls

235 lines (172 loc) · 6.18 KB

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.