Skip to content

Commit 2025d18

Browse files
authored
Merge pull request SciSharp#1009 from gunpal5/master
fix: Google realtime communication
2 parents d88e762 + a2721f1 commit 2025d18

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/Infrastructure/BotSharp.Core.Realtime/Services/WaveStreamChannel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task ConnectAsync(string conversationId)
2525
_waveIn = new WaveInEvent
2626
{
2727
DeviceNumber = 0, // Default recording device
28-
WaveFormat = new WaveFormat(24000, 16, 1), // 24000 Hz, 16-bit PCM, Mono
28+
WaveFormat = new WaveFormat(16000, 16, 1), // 24000 Hz, 16-bit PCM, Mono
2929
BufferMilliseconds = 100
3030
};
3131

src/Plugins/BotSharp.Plugin.GoogleAI/Providers/Realtime/RealTimeCompletionProvider.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public async Task Connect(RealtimeHubConnection conn,
7979

8080
await AttachEvents(_client);
8181

82-
await _client.ConnectAsync();
82+
await _client.ConnectAsync(false);
8383
}
8484

8585
public async Task Disconnect()
@@ -96,7 +96,7 @@ public async Task AppenAudioBuffer(string message)
9696
public async Task AppenAudioBuffer(ArraySegment<byte> data, int length)
9797
{
9898
var buffer = data.AsSpan(0, length).ToArray();
99-
await _client.SendAudioAsync(buffer);
99+
await _client.SendAudioAsync(buffer,"audio/pcm;rate=16000");
100100
}
101101

102102
public async Task TriggerModelInference(string? instructions = null)
@@ -285,10 +285,14 @@ await HookEmitter.Emit<IContentGeneratingHook>(_services,
285285
});
286286
}
287287

288+
// if(request.Tools.Count == 0)
289+
// request.Tools = null;
290+
// config.MaxOutputTokens = null;
291+
288292
await _client.SendSetupAsync(new BidiGenerateContentSetup()
289293
{
290294
GenerationConfig = config,
291-
Model = Model,
295+
Model = Model.ToModelId(),
292296
SystemInstruction = request.SystemInstruction,
293297
Tools = request.Tools?.ToArray(),
294298
});

tests/BotSharp.Test.RealtimeVoice/appsettings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"Models": [
2828
{
2929
"Id": "gemini-2.0",
30-
"Name": "gemini-2.0-flash-exp",
30+
"Name": "gemini-2.0-flash-live-001",
3131
"Version": "20240620",
3232
"ApiKey": "",
3333
"Type": "realtime",
@@ -48,8 +48,11 @@
4848
},
4949

5050
"RealtimeModel": {
51+
"Provider": "google-ai",
52+
"Model": "gemini-2.0-flash-live-001",
5153
"InputAudioFormat": "pcm16",
52-
"OutputAudioFormat": "pcm16"
54+
"OutputAudioFormat": "pcm16",
55+
"InterruptResponse": false,
5356
},
5457

5558
"PluginLoader": {

0 commit comments

Comments
 (0)