fysh711426 / EdgeTTS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EdgeTTS

This repo is C# implementation of edge-tts.

EdgeTTS allows you to use Microsoft Edge's online text-to-speech service from C#.


Nuget install

PM> Install-Package EdgeTTS

Example

var OUTPUT_FILE = "hello.mp3";
var communicate = new Communicate(
    "hello world", "zh-CN-YunxiNeural");
await communicate.Save(OUTPUT_FILE);

Stream example

var communicate = new Communicate(TEXT, "zh-CN-YunxiNeural");

using (var stream = File.Create(OUTPUT_FILE))
{
    await communicate.Stream((result) =>
    {
        if (result.Type == "audio")
            result.Data?.CopyTo(stream);

        if (result.Type == "WordBoundary")
            Console.WriteLine(JsonConvert.SerializeObject(result));
    });
}

VoicesManager example

// List voices
var list = await VoicesManager.ListVoices();

// Finds all matching voices
var manager = await VoicesManager.Create();
var voices = manager.Find(gender: "Male", language: "es");

// Also supports Locales
// var voices = manager.Find(gender: "Female", locale: "es-AR");

var communicate = new Communicate(TEXT, voices[0].Name);
await communicate.Save(OUTPUT_FILE);

SubMaker example

var submaker = new SubMaker();
var communicate = new Communicate(TEXT, "zh-CN-YunxiNeural");

using (var stream = File.Create(OUTPUT_FILE))
{
    await communicate.Stream((result) =>
    {
        if (result.Type == "audio")
            result.Data?.CopyTo(stream);

        if (result.Type == "WordBoundary")
            submaker.CreateSub(
                (result.Offset, result.Duration), result.Text);
    });
}

using (var writer = File.CreateText(WEBVTT_FILE))
{
    await writer.WriteAsync(submaker.GenerateSubs());
}

Declare

This repo is not an official edge-tts product.

About

License:GNU General Public License v3.0


Languages

Language:C# 100.0%