fix: Google realtime communication

This commit is contained in:
Gunpal Jain 2025-04-14 10:54:05 +05:30
parent d88e762fdb
commit a2721f1980
3 changed files with 13 additions and 6 deletions

View file

@ -25,7 +25,7 @@ public class WaveStreamChannel : IStreamChannel
_waveIn = new WaveInEvent _waveIn = new WaveInEvent
{ {
DeviceNumber = 0, // Default recording device DeviceNumber = 0, // Default recording device
WaveFormat = new WaveFormat(24000, 16, 1), // 24000 Hz, 16-bit PCM, Mono WaveFormat = new WaveFormat(16000, 16, 1), // 24000 Hz, 16-bit PCM, Mono
BufferMilliseconds = 100 BufferMilliseconds = 100
}; };

View file

@ -79,7 +79,7 @@ public class GoogleRealTimeProvider : IRealTimeCompletion
await AttachEvents(_client); await AttachEvents(_client);
await _client.ConnectAsync(); await _client.ConnectAsync(false);
} }
public async Task Disconnect() public async Task Disconnect()
@ -96,7 +96,7 @@ public class GoogleRealTimeProvider : IRealTimeCompletion
public async Task AppenAudioBuffer(ArraySegment<byte> data, int length) public async Task AppenAudioBuffer(ArraySegment<byte> data, int length)
{ {
var buffer = data.AsSpan(0, length).ToArray(); var buffer = data.AsSpan(0, length).ToArray();
await _client.SendAudioAsync(buffer); await _client.SendAudioAsync(buffer,"audio/pcm;rate=16000");
} }
public async Task TriggerModelInference(string? instructions = null) public async Task TriggerModelInference(string? instructions = null)
@ -285,10 +285,14 @@ public class GoogleRealTimeProvider : IRealTimeCompletion
}); });
} }
// if(request.Tools.Count == 0)
// request.Tools = null;
// config.MaxOutputTokens = null;
await _client.SendSetupAsync(new BidiGenerateContentSetup() await _client.SendSetupAsync(new BidiGenerateContentSetup()
{ {
GenerationConfig = config, GenerationConfig = config,
Model = Model, Model = Model.ToModelId(),
SystemInstruction = request.SystemInstruction, SystemInstruction = request.SystemInstruction,
Tools = request.Tools?.ToArray(), Tools = request.Tools?.ToArray(),
}); });

View file

@ -27,7 +27,7 @@
"Models": [ "Models": [
{ {
"Id": "gemini-2.0", "Id": "gemini-2.0",
"Name": "gemini-2.0-flash-exp", "Name": "gemini-2.0-flash-live-001",
"Version": "20240620", "Version": "20240620",
"ApiKey": "", "ApiKey": "",
"Type": "realtime", "Type": "realtime",
@ -48,8 +48,11 @@
}, },
"RealtimeModel": { "RealtimeModel": {
"Provider": "google-ai",
"Model": "gemini-2.0-flash-live-001",
"InputAudioFormat": "pcm16", "InputAudioFormat": "pcm16",
"OutputAudioFormat": "pcm16" "OutputAudioFormat": "pcm16",
"InterruptResponse": false,
}, },
"PluginLoader": { "PluginLoader": {