28 lines
669 B
C#
28 lines
669 B
C#
|
|
using System.Runtime.CompilerServices;
|
||
|
|
|
||
|
|
namespace Robovoice.Core;
|
||
|
|
|
||
|
|
public interface ITtsEngine : IAsyncDisposable
|
||
|
|
{
|
||
|
|
string Name { get; }
|
||
|
|
|
||
|
|
int SampleRate { get; }
|
||
|
|
|
||
|
|
Task InitializeAsync(CancellationToken ct = default);
|
||
|
|
|
||
|
|
IAsyncEnumerable<AudioChunk> SynthesizeAsync(
|
||
|
|
string text,
|
||
|
|
CancellationToken ct = default);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static class TtsEngineExtensions
|
||
|
|
{
|
||
|
|
public static ConfiguredCancelableAsyncEnumerable<AudioChunk> SynthesizeAsync(
|
||
|
|
this ITtsEngine engine,
|
||
|
|
string text,
|
||
|
|
CancellationToken ct = default)
|
||
|
|
{
|
||
|
|
return engine.SynthesizeAsync(text, ct).ConfigureAwait(false).WithCancellation(ct);
|
||
|
|
}
|
||
|
|
}
|