From a5d179d60dc01ba88055d037ebc5c969b5bf01d6 Mon Sep 17 00:00:00 2001
From: BonzY <38046279+BonzY1337@users.noreply.github.com>
Date: Fri, 4 Jul 2025 15:30:49 +0530
Subject: [PATCH] Audio (bugged)
File Already in use error.
---
highminded.csproj | 25 +++++-----
ui/controls/ChatUserControl.axaml.cs | 57 +++++++++++++++++++++++
ui/controls/SettingsUserControl.axaml | 19 +++++---
ui/windows/MainWindow.axaml | 8 ++++
ui/windows/MainWindow.axaml.cs | 15 ++++++
utils/AudioCapture.cs | 66 +++++++++++++++++++++++++++
utils/SetttingsManager.cs | 3 +-
7 files changed, 173 insertions(+), 20 deletions(-)
create mode 100644 utils/AudioCapture.cs
diff --git a/highminded.csproj b/highminded.csproj
index 743ff24..241e9f7 100644
--- a/highminded.csproj
+++ b/highminded.csproj
@@ -17,23 +17,24 @@
-
-
-
-
-
+
+
+
+
+
None
All
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/ui/controls/ChatUserControl.axaml.cs b/ui/controls/ChatUserControl.axaml.cs
index 371da33..839cfea 100644
--- a/ui/controls/ChatUserControl.axaml.cs
+++ b/ui/controls/ChatUserControl.axaml.cs
@@ -10,18 +10,75 @@ using highminded.utils;
using OpenAI.Chat;
using Markdig;
using Markdown.ColorCode;
+using System.Net.Http;
namespace highminded.ui.controls;
public partial class ChatUserControl : UserControl
{
private readonly MarkdownPipeline _pipeline = null!;
+ private AudioCapture.AudioRecorder? _audioRecorder;
+ private const string AudioFilePath = "output.wav";
public ChatUserControl()
{
InitializeComponent();
_pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().UseColorCode().Build();
}
+
+
+ public void StartRecord()
+ {
+ _audioRecorder = new AudioCapture.AudioRecorder(AudioFilePath);
+ _audioRecorder.StartRecording();
+ }
+
+ public void StopRecord()
+ {
+ if (_audioRecorder != null)
+ {
+ _audioRecorder.StopRecording();
+ OnRecordingStopped(null, EventArgs.Empty); // Manually invoke the method after stopping the recording kyuki already in use bata ra hai
+ }
+ }
+
+ private void OnRecordingStopped(object? sender, EventArgs e)
+ {
+ _audioRecorder = null;
+ SendAudio();
+ }
+ public async void SendAudio()
+ {
+ try
+ {
+ if (!File.Exists("output.wav"))
+ throw new Exception("Audio file not found");
+
+
+ var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
+ var fileName = "output.wav";
+ var destPath = Path.Combine(Environment.CurrentDirectory, fileName);
+ File.Copy("output.wav", destPath, true);
+
+ await using Stream audioStream = File.OpenRead("output.wav");
+ var audioBytes = await BinaryData.FromStreamAsync(audioStream);
+
+ List messages =
+ [
+ new UserChatMessage(
+ ChatMessageContentPart.CreateTextPart(InMemoryDb.Obj.SettingsManager.Settings.AudioPrompt),
+ ChatMessageContentPart.CreateInputAudioPart(audioBytes, "audio/wav")
+ )
+ ];
+
+ await ProcessChatStreamAsync(messages);
+ }
+ catch (Exception err)
+ {
+ ResultBlock.Text = err.Message;
+ }
+ }
+
public async void SendScreenshot()
{
diff --git a/ui/controls/SettingsUserControl.axaml b/ui/controls/SettingsUserControl.axaml
index f6bb01c..2275e34 100644
--- a/ui/controls/SettingsUserControl.axaml
+++ b/ui/controls/SettingsUserControl.axaml
@@ -21,13 +21,18 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ui/windows/MainWindow.axaml b/ui/windows/MainWindow.axaml
index 35e6814..bfdedda 100644
--- a/ui/windows/MainWindow.axaml
+++ b/ui/windows/MainWindow.axaml
@@ -39,6 +39,14 @@
+
+
+
+
+
+