Aquila.TTSandSTT
1.0.5
dotnet add package Aquila.TTSandSTT --version 1.0.5
NuGet\Install-Package Aquila.TTSandSTT -Version 1.0.5
<PackageReference Include="Aquila.TTSandSTT" Version="1.0.5" />
<PackageVersion Include="Aquila.TTSandSTT" Version="1.0.5" />
<PackageReference Include="Aquila.TTSandSTT" />
paket add Aquila.TTSandSTT --version 1.0.5
#r "nuget: Aquila.TTSandSTT, 1.0.5"
#:package Aquila.TTSandSTT@1.0.5
#addin nuget:?package=Aquila.TTSandSTT&version=1.0.5
#tool nuget:?package=Aquila.TTSandSTT&version=1.0.5
Aquila.TTSandSTT Library
Cross-platform TTS (Text-to-Speech) and STT (Speech-to-Text) library for .NET MAUI / .NET 9.0
Supports Android fully and can be extended for other platforms (Windows, iOS, macOS).
Table of Contents
-
- Speak
- Listen
- Save to File
Overview
Aquila.TTSandSTT provides a unified interface for:
- Text-to-Speech (TTS): Speak any string or save it as audio.
- Speech-to-Text (STT): Capture spoken input and return text.
It is designed as a singleton service for easy DI integration in .NET MAUI apps.
Installation
- Add
Aquila.TTSandSTTproject/library to your solution. - Add reference to your MAUI project.
- Ensure your TargetFrameworks include Android:
<TargetFrameworks>net9.0-android;net9.0-windows10.0.19041.0</TargetFrameworks>
Usage
1. Register the service (MAUI MauiProgram.cs)
using Aquila.TTSandSTT;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
// Register the TTS/STT service
builder.Services.AddSingleton(sp => ServiceHelper.GetVoiceService());
builder
.UseMauiApp<App>()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
});
return builder.Build();
}
}
2. Inject into MainPage
using Aquila.TTSandSTT.Interfaces;
public partial class MainPage : ContentPage
{
private readonly IAquilaVoice _voice;
public MainPage(IAquilaVoice voice)
{
InitializeComponent();
_voice = voice;
}
}
3. Speak Text
await _voice.SpeakAsync("Hello World!", rate: 1.0f, pitch: 1.0f);
4. Listen (Speech-to-Text)
string result = await _voice.ListenAsync(language: "en-US", timeoutSeconds: 10);
Console.WriteLine(result);
5. Save Speech to File
string path = Path.Combine(FileSystem.AppDataDirectory, "speech.wav");
await _voice.SaveSpeechToFileAsync("Hello World", path);
Console.WriteLine($"Saved to {path}");
API Reference
IAquilaVoice
| Method | Description | Parameters | Return |
|---|---|---|---|
Task SpeakAsync(string text, string language = "en-US", float pitch = 1.0f, float rate = 1.0f) |
Speak text aloud | text, language, pitch, rate |
Task |
Task<string> ListenAsync(string language = "en-US", int timeoutSeconds = 10) |
Capture speech and return as text | language, timeoutSeconds |
Task<string> |
Task<string> SaveSpeechToFileAsync(string text, string filePath, string language = "en-US", float pitch = 1.0f, float rate = 1.0f) |
Save speech to audio file | text, filePath, language, pitch, rate |
Task<string> |
bool IsSpeaking |
Check if TTS is currently speaking | — | bool |
Platform-specific Notes
- Android: Full TTS & STT support.
- Windows: Currently TTS/STT methods throw
NotSupportedException. - iOS/macOS: Can implement using
AVSpeechSynthesizerandSpeechRecognizerin future versions.
Permissions
For Android, add these to AndroidManifest.xml:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
Note: Runtime permission request is required on Android 6.0+:
var status = await Permissions.RequestAsync<Permissions.Microphone>();
if (status != PermissionStatus.Granted)
{
await DisplayAlert("Permission", "Microphone permission is required", "OK");
}
Troubleshooting
Ambiguous reference errors (
TextToSpeech,Locale,Application): Use fully qualified names:var tts = new global::Android.Speech.Tts.TextToSpeech(...); var locale = new global::Java.Util.Locale("en-US"); var context = global::Android.App.Application.Context;Windows compilation errors: Wrap Android-specific code in
#if ANDROID ... #endif.STT returns empty: Ensure microphone permission is granted and device supports speech recognition.
Example MAUI Page
<VerticalStackLayout Padding="20">
<Editor x:Name="InputText" HeightRequest="100" Placeholder="Enter text"/>
<Button Text="Speak" Clicked="SpeakClicked"/>
<Button Text="Listen" Clicked="ListenClicked"/>
<Label x:Name="ResultText"/>
</VerticalStackLayout>
private async void SpeakClicked(object sender, EventArgs e)
{
await _voice.SpeakAsync(InputText.Text);
}
private async void ListenClicked(object sender, EventArgs e)
{
string text = await _voice.ListenAsync();
ResultText.Text = text;
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0-android35.0 is compatible. net9.0-windows10.0.19041 is compatible. net10.0-android was computed. net10.0-windows was computed. |
-
net9.0-android35.0
- Microsoft.Maui.Controls (>= 9.0.120)
-
net9.0-windows10.0.19041
- Microsoft.Maui.Controls (>= 9.0.120)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.