Skip to content

Commit f08ec24

Browse files
Merge branch 'main' into 22-agent-knowledge-base
2 parents 3050c77 + 03098b2 commit f08ec24

21 files changed

Lines changed: 622 additions & 5 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
@@ -71,6 +71,7 @@ static void RegisterExamples(IServiceCollection services)
7171
services.AddTransient<ChatWithImageGenGeminiExample>();
7272
services.AddTransient<ChatWithFilesExampleGemini>();
7373
services.AddTransient<ChatWithReasoningDeepSeekExample>();
74+
services.AddTransient<ChatWithTextToSpeechExample>();
7475
services.AddTransient<ChatExampleGroqCloud>();
7576
}
7677

@@ -163,6 +164,8 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
163164
("\u25a0 DeepSeek Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningDeepSeekExample>()),
164165
("\u25a0 GroqCloud Chat", serviceProvider.GetRequiredService<ChatExampleGroqCloud>()),
165166
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
167+
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>()),
168+
("\u25a0 Chat with TTS example", serviceProvider.GetRequiredService<ChatWithTextToSpeechExample>()),
166169
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>())
167170
};
168171
}

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/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+
}

src/MaIN.Domain/Entities/Voice.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace MaIN.Domain.Entities;
2+
3+
public class Voice
4+
{
5+
public required string Name { get; set; }
6+
public required float[,,] Features { get; set; }
7+
}

0 commit comments

Comments
 (0)