Skip to content

Commit 03098b2

Browse files
Merge pull request #82 from wisedev-code/feature/tts
Feature/tts
2 parents 3981efc + 88ef18b commit 03098b2

22 files changed

Lines changed: 623 additions & 6 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using MaIN.Core.Hub;
2+
using MaIN.Domain.Entities;
3+
using MaIN.Services.Services.TTSService;
4+
5+
namespace Examples;
6+
7+
public class ChatWithTextToSpeechExample : IExample
8+
{
9+
private const string VoicePath = "<your-path-to-voices>";
10+
11+
public async Task Start()
12+
{
13+
Console.WriteLine("ChatWithTextToSpeech is running! Put on your headphones and press any key.");
14+
Console.ReadKey();
15+
16+
VoiceService.SetVoicesPath(VoicePath);
17+
var voice = VoiceService.GetVoice("af_heart")
18+
.MixWith(VoiceService.GetVoice("bf_emma"));
19+
20+
await AIHub.Chat().WithModel("gemma2:2b")
21+
.WithMessage("Generate a 4 sentence poem.")
22+
.Speak(new TextToSpeechParams("kokoro:82m", voice, true))
23+
.CompleteAsync(interactive: true);
24+
25+
Console.WriteLine("Done!");
26+
Console.ReadKey();
27+
}
28+
}

Examples/Examples/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static void RegisterExamples(IServiceCollection services)
6767
services.AddTransient<ChatWithImageGenGeminiExample>();
6868
services.AddTransient<ChatWithFilesExampleGemini>();
6969
services.AddTransient<ChatWithReasoningDeepSeekExample>();
70+
services.AddTransient<ChatWithTextToSpeechExample>();
7071
services.AddTransient<ChatExampleGroqCloud>();
7172
}
7273

@@ -156,6 +157,8 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
156157
("\u25a0 DeepSeek Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningDeepSeekExample>()),
157158
("\u25a0 GroqCloud Chat", serviceProvider.GetRequiredService<ChatExampleGroqCloud>()),
158159
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
160+
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>()),
161+
("\u25a0 Chat with TTS example", serviceProvider.GetRequiredService<ChatWithTextToSpeechExample>()),
159162
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>())
160163
};
161164
}

Examples/Examples/appsettings.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
}
77
},
88
"MaIN": {
9-
"ImageGenUrl": "http://localhost:5003",
10-
// "SqliteSettings": {
11-
// "ConnectionString": "Data Source=Main_test.db"
12-
// }
9+
"ImageGenUrl": "http://localhost:5003"
1310
},
1411
"AllowedHosts": "*"
1512
}

Releases/0.4.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.3.1 release
2+
3+
- Added TextToSpeech functionality to using Kokoro TTS model.

src/MaIN.Core/.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>MaIN.NET</id>
5-
<version>0.3.1</version>
5+
<version>0.4.0</version>
66
<authors>Wisedev</authors>
77
<owners>Wisedev</owners>
88
<icon>favicon.png</icon>

src/MaIN.Core/Hub/Contexts/ChatContext.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using MaIN.Domain.Models;
44
using MaIN.Services;
55
using MaIN.Services.Constants;
6-
using MaIN.Services.Dtos;
76
using MaIN.Services.Services.Abstract;
87
using MaIN.Services.Services.Models;
98
using FileInfo = MaIN.Domain.Entities.FileInfo;
@@ -61,6 +60,14 @@ public ChatContext WithCustomModel(string model, string path, string? mmProject
6160
return this;
6261
}
6362

63+
public ChatContext Speak(TextToSpeechParams textToSpeechParams)
64+
{
65+
_chat.Visual = false;
66+
_chat.TextToSpeechParams = textToSpeechParams;
67+
68+
return this;
69+
}
70+
6471
public ChatContext WithBackend(BackendType backendType)
6572
{
6673
_chat.Backend = backendType;
@@ -151,6 +158,7 @@ public ChatContext WithFiles(List<string> filePaths, bool preProcess = false)
151158
public ChatContext EnableVisual()
152159
{
153160
_chat.Visual = true;
161+
_chat.TextToSpeechParams = null;
154162
return this;
155163
}
156164

src/MaIN.Domain/Configuration/MaINSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class MaINSettings
1616
public FileSystemSettings? FileSystemSettings { get; set; }
1717
public SqliteSettings? SqliteSettings { get; set; }
1818
public SqlSettings? SqlSettings { get; set; }
19+
public string? VoicesPath { get; set; }
1920
}
2021

2122
public enum BackendType

src/MaIN.Domain/Entities/Chat.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class Chat
1313
public bool Visual { get; set; }
1414
public InferenceParams InterferenceParams { get; set; } = new();
1515
public MemoryParams MemoryParams { get; set; } = new();
16+
public TextToSpeechParams? TextToSpeechParams { get; set; }
1617
public Dictionary<string, string> Properties { get; init; } = [];
1718
public List<string> Memory { get; } = [];
1819
public BackendType? Backend { get; set; }

src/MaIN.Domain/Entities/Message.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public Message()
2020
public bool Tool { get; init; }
2121
public DateTime Time { get; set; }
2222
public byte[]? Image { get; init; }
23+
public byte[]? Speech { get; set; }
2324
public List<FileInfo>? Files { get; set; }
2425
public Dictionary<string, string> Properties { get; set; } = [];
2526

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace MaIN.Domain.Entities;
2+
3+
public class TextToSpeechParams
4+
{
5+
public string Model { get; set; }
6+
public Voice Voice { get; set; }
7+
public bool Playback { get; set; }
8+
9+
public TextToSpeechParams(string model, Voice voice, bool playback = false)
10+
{
11+
Model = model;
12+
Voice = voice;
13+
Playback = playback;
14+
}
15+
}

0 commit comments

Comments
 (0)