Compare commits
16 Commits
41a53d35b0
...
mistress
| Author | SHA1 | Date | |
|---|---|---|---|
| a80bd8f669 | |||
| c174576e14 | |||
| b8ee014cc3 | |||
| cc9fc95519 | |||
| 411f1c0952 | |||
| b40a06b01b | |||
| b6361ec080 | |||
| 84474731e7 | |||
| b3e0fe3b30 | |||
| 20e5c6c542 | |||
| 56bf55ba42 | |||
| 004cd10f78 | |||
| 8473ab6ba5 | |||
| e09eb804b6 | |||
| b4f05d6301 | |||
| caad0ed50e |
Generated
+20
-75
@@ -9,21 +9,15 @@ partial class MainForm
|
|||||||
private TextBox txtPttKey = null!;
|
private TextBox txtPttKey = null!;
|
||||||
private Label lblVoice = null!;
|
private Label lblVoice = null!;
|
||||||
private ComboBox cmbVoice = null!;
|
private ComboBox cmbVoice = null!;
|
||||||
private Button btnTestVoice = null!;
|
|
||||||
private Button btnManageVoices = null!;
|
private Button btnManageVoices = null!;
|
||||||
private Label lblOutput = null!;
|
private Label lblOutput = null!;
|
||||||
private ComboBox cmbOutput = null!;
|
private ComboBox cmbOutput = null!;
|
||||||
private Label lblFile = null!;
|
|
||||||
private Button btnBrowseFile = null!;
|
|
||||||
private Label lblFileName = null!;
|
|
||||||
private Label lblServer = null!;
|
private Label lblServer = null!;
|
||||||
private TextBox txtSttEndpoint = null!;
|
private TextBox txtSttEndpoint = null!;
|
||||||
private Label lblLineStatus = null!;
|
private Button btnLock = null!;
|
||||||
private RichTextBox txtLog = null!;
|
private RichTextBox txtLog = null!;
|
||||||
private CheckBox chkMinimizeToTray = null!;
|
private CheckBox chkMinimizeToTray = null!;
|
||||||
private Button btnClearLog = null!;
|
private Button btnClearLog = null!;
|
||||||
private Label lblTextInput = null!;
|
|
||||||
private TextBox txtTextInput = null!;
|
|
||||||
private Label lblNoise = null!;
|
private Label lblNoise = null!;
|
||||||
private TrackBar trkNoise = null!;
|
private TrackBar trkNoise = null!;
|
||||||
private Label lblNoiseVal = null!;
|
private Label lblNoiseVal = null!;
|
||||||
@@ -49,21 +43,15 @@ partial class MainForm
|
|||||||
txtPttKey = new TextBox();
|
txtPttKey = new TextBox();
|
||||||
lblVoice = new Label();
|
lblVoice = new Label();
|
||||||
cmbVoice = new ComboBox();
|
cmbVoice = new ComboBox();
|
||||||
btnTestVoice = new Button();
|
|
||||||
btnManageVoices = new Button();
|
btnManageVoices = new Button();
|
||||||
lblOutput = new Label();
|
lblOutput = new Label();
|
||||||
cmbOutput = new ComboBox();
|
cmbOutput = new ComboBox();
|
||||||
lblFile = new Label();
|
|
||||||
btnBrowseFile = new Button();
|
|
||||||
lblFileName = new Label();
|
|
||||||
lblServer = new Label();
|
lblServer = new Label();
|
||||||
txtSttEndpoint = new TextBox();
|
txtSttEndpoint = new TextBox();
|
||||||
lblLineStatus = new Label();
|
btnLock = new Button();
|
||||||
txtLog = new RichTextBox();
|
txtLog = new RichTextBox();
|
||||||
chkMinimizeToTray = new CheckBox();
|
chkMinimizeToTray = new CheckBox();
|
||||||
btnClearLog = new Button();
|
btnClearLog = new Button();
|
||||||
lblTextInput = new Label();
|
|
||||||
txtTextInput = new TextBox();
|
|
||||||
lblNoise = new Label();
|
lblNoise = new Label();
|
||||||
trkNoise = new TrackBar();
|
trkNoise = new TrackBar();
|
||||||
lblNoiseVal = new Label();
|
lblNoiseVal = new Label();
|
||||||
@@ -100,64 +88,38 @@ partial class MainForm
|
|||||||
cmbVoice.Size = new Size(200, 23);
|
cmbVoice.Size = new Size(200, 23);
|
||||||
cmbVoice.DropDownStyle = ComboBoxStyle.DropDownList;
|
cmbVoice.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
|
||||||
// btnTestVoice
|
|
||||||
btnTestVoice.Text = "Test";
|
|
||||||
btnTestVoice.Location = new Point(423, 11);
|
|
||||||
btnTestVoice.Size = new Size(45, 25);
|
|
||||||
btnTestVoice.UseVisualStyleBackColor = true;
|
|
||||||
|
|
||||||
// btnManageVoices
|
// btnManageVoices
|
||||||
btnManageVoices.Text = "Add/Remove...";
|
btnManageVoices.Text = "Add/Remove...";
|
||||||
btnManageVoices.Location = new Point(474, 11);
|
btnManageVoices.Location = new Point(423, 11);
|
||||||
btnManageVoices.Size = new Size(95, 25);
|
btnManageVoices.Size = new Size(95, 25);
|
||||||
btnManageVoices.UseVisualStyleBackColor = true;
|
btnManageVoices.UseVisualStyleBackColor = true;
|
||||||
|
|
||||||
// lblOutput
|
// lblOutput
|
||||||
lblOutput.Text = "Output:";
|
lblOutput.Text = "Output:";
|
||||||
lblOutput.Location = new Point(580, 15);
|
lblOutput.Location = new Point(530, 15);
|
||||||
lblOutput.Size = new Size(50, 23);
|
lblOutput.Size = new Size(50, 23);
|
||||||
lblOutput.TextAlign = ContentAlignment.MiddleLeft;
|
lblOutput.TextAlign = ContentAlignment.MiddleLeft;
|
||||||
|
|
||||||
// cmbOutput
|
// cmbOutput
|
||||||
cmbOutput.Location = new Point(633, 12);
|
cmbOutput.Location = new Point(583, 12);
|
||||||
cmbOutput.Size = new Size(180, 23);
|
cmbOutput.Size = new Size(150, 23);
|
||||||
cmbOutput.DropDownStyle = ComboBoxStyle.DropDownList;
|
cmbOutput.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
|
|
||||||
// lblFile
|
|
||||||
lblFile.Text = "Text File:";
|
|
||||||
lblFile.Location = new Point(12, 48);
|
|
||||||
lblFile.Size = new Size(60, 23);
|
|
||||||
lblFile.TextAlign = ContentAlignment.MiddleLeft;
|
|
||||||
|
|
||||||
// btnBrowseFile
|
|
||||||
btnBrowseFile.Text = "Browse...";
|
|
||||||
btnBrowseFile.Location = new Point(75, 45);
|
|
||||||
btnBrowseFile.Size = new Size(75, 25);
|
|
||||||
btnBrowseFile.UseVisualStyleBackColor = true;
|
|
||||||
|
|
||||||
// lblFileName
|
|
||||||
lblFileName.Text = "(none)";
|
|
||||||
lblFileName.Location = new Point(155, 48);
|
|
||||||
lblFileName.Size = new Size(280, 23);
|
|
||||||
lblFileName.TextAlign = ContentAlignment.MiddleLeft;
|
|
||||||
lblFileName.ForeColor = Color.Gray;
|
|
||||||
|
|
||||||
// lblServer
|
// lblServer
|
||||||
lblServer.Text = "STT:";
|
lblServer.Text = "STT:";
|
||||||
lblServer.Location = new Point(440, 48);
|
lblServer.Location = new Point(12, 48);
|
||||||
lblServer.Size = new Size(35, 23);
|
lblServer.Size = new Size(35, 23);
|
||||||
lblServer.TextAlign = ContentAlignment.MiddleLeft;
|
lblServer.TextAlign = ContentAlignment.MiddleLeft;
|
||||||
|
|
||||||
// txtSttEndpoint
|
// txtSttEndpoint
|
||||||
txtSttEndpoint.Location = new Point(478, 45);
|
txtSttEndpoint.Location = new Point(50, 45);
|
||||||
txtSttEndpoint.Size = new Size(185, 23);
|
txtSttEndpoint.Size = new Size(200, 23);
|
||||||
|
|
||||||
// lblLineStatus
|
// btnLock
|
||||||
lblLineStatus.Text = "";
|
btnLock.Text = "Lock Model";
|
||||||
lblLineStatus.Location = new Point(645, 48);
|
btnLock.Location = new Point(260, 44);
|
||||||
lblLineStatus.Size = new Size(160, 23);
|
btnLock.Size = new Size(90, 25);
|
||||||
lblLineStatus.TextAlign = ContentAlignment.MiddleRight;
|
btnLock.UseVisualStyleBackColor = true;
|
||||||
lblLineStatus.ForeColor = Color.DarkBlue;
|
|
||||||
|
|
||||||
// lblNoise
|
// lblNoise
|
||||||
lblNoise.Text = "Noise:";
|
lblNoise.Text = "Noise:";
|
||||||
@@ -165,7 +127,7 @@ partial class MainForm
|
|||||||
lblNoise.Size = new Size(40, 23);
|
lblNoise.Size = new Size(40, 23);
|
||||||
lblNoise.TextAlign = ContentAlignment.MiddleLeft;
|
lblNoise.TextAlign = ContentAlignment.MiddleLeft;
|
||||||
|
|
||||||
// trkNoise (0-1000 → 0.0-1.0, default 667)
|
// trkNoise
|
||||||
trkNoise.Location = new Point(52, 78);
|
trkNoise.Location = new Point(52, 78);
|
||||||
trkNoise.Size = new Size(120, 45);
|
trkNoise.Size = new Size(120, 45);
|
||||||
trkNoise.Minimum = 0;
|
trkNoise.Minimum = 0;
|
||||||
@@ -186,7 +148,7 @@ partial class MainForm
|
|||||||
lblSpeed.Size = new Size(40, 23);
|
lblSpeed.Size = new Size(40, 23);
|
||||||
lblSpeed.TextAlign = ContentAlignment.MiddleLeft;
|
lblSpeed.TextAlign = ContentAlignment.MiddleLeft;
|
||||||
|
|
||||||
// trkSpeed (50-300 → 0.5-3.0, default 100)
|
// trkSpeed
|
||||||
trkSpeed.Location = new Point(260, 78);
|
trkSpeed.Location = new Point(260, 78);
|
||||||
trkSpeed.Size = new Size(120, 45);
|
trkSpeed.Size = new Size(120, 45);
|
||||||
trkSpeed.Minimum = 50;
|
trkSpeed.Minimum = 50;
|
||||||
@@ -207,7 +169,7 @@ partial class MainForm
|
|||||||
lblNoiseW.Size = new Size(45, 23);
|
lblNoiseW.Size = new Size(45, 23);
|
||||||
lblNoiseW.TextAlign = ContentAlignment.MiddleLeft;
|
lblNoiseW.TextAlign = ContentAlignment.MiddleLeft;
|
||||||
|
|
||||||
// trkNoiseW (0-1000 → 0.0-1.0, default 800)
|
// trkNoiseW
|
||||||
trkNoiseW.Location = new Point(475, 78);
|
trkNoiseW.Location = new Point(475, 78);
|
||||||
trkNoiseW.Size = new Size(120, 45);
|
trkNoiseW.Size = new Size(120, 45);
|
||||||
trkNoiseW.Minimum = 0;
|
trkNoiseW.Minimum = 0;
|
||||||
@@ -223,19 +185,8 @@ partial class MainForm
|
|||||||
lblNoiseWVal.TextAlign = ContentAlignment.MiddleLeft;
|
lblNoiseWVal.TextAlign = ContentAlignment.MiddleLeft;
|
||||||
|
|
||||||
// txtLog
|
// txtLog
|
||||||
txtLog.Location = new Point(12, 149);
|
txtLog.Location = new Point(12, 121);
|
||||||
txtLog.Size = new Size(800, 310);
|
txtLog.Size = new Size(800, 338);
|
||||||
|
|
||||||
// lblTextInput
|
|
||||||
lblTextInput.Text = "Text:";
|
|
||||||
lblTextInput.Location = new Point(12, 121);
|
|
||||||
lblTextInput.Size = new Size(35, 23);
|
|
||||||
lblTextInput.TextAlign = ContentAlignment.MiddleLeft;
|
|
||||||
|
|
||||||
// txtTextInput
|
|
||||||
txtTextInput.Location = new Point(50, 118);
|
|
||||||
txtTextInput.Size = new Size(762, 23);
|
|
||||||
|
|
||||||
txtLog.ReadOnly = true;
|
txtLog.ReadOnly = true;
|
||||||
txtLog.Font = new Font("Consolas", 9F);
|
txtLog.Font = new Font("Consolas", 9F);
|
||||||
txtLog.BackColor = Color.FromArgb(30, 30, 30);
|
txtLog.BackColor = Color.FromArgb(30, 30, 30);
|
||||||
@@ -261,16 +212,12 @@ partial class MainForm
|
|||||||
Controls.Add(txtPttKey);
|
Controls.Add(txtPttKey);
|
||||||
Controls.Add(lblVoice);
|
Controls.Add(lblVoice);
|
||||||
Controls.Add(cmbVoice);
|
Controls.Add(cmbVoice);
|
||||||
Controls.Add(btnTestVoice);
|
|
||||||
Controls.Add(btnManageVoices);
|
Controls.Add(btnManageVoices);
|
||||||
Controls.Add(lblOutput);
|
Controls.Add(lblOutput);
|
||||||
Controls.Add(cmbOutput);
|
Controls.Add(cmbOutput);
|
||||||
Controls.Add(lblFile);
|
|
||||||
Controls.Add(btnBrowseFile);
|
|
||||||
Controls.Add(lblFileName);
|
|
||||||
Controls.Add(lblServer);
|
Controls.Add(lblServer);
|
||||||
Controls.Add(txtSttEndpoint);
|
Controls.Add(txtSttEndpoint);
|
||||||
Controls.Add(lblLineStatus);
|
Controls.Add(btnLock);
|
||||||
Controls.Add(lblNoise);
|
Controls.Add(lblNoise);
|
||||||
Controls.Add(trkNoise);
|
Controls.Add(trkNoise);
|
||||||
Controls.Add(lblNoiseVal);
|
Controls.Add(lblNoiseVal);
|
||||||
@@ -280,8 +227,6 @@ partial class MainForm
|
|||||||
Controls.Add(lblNoiseW);
|
Controls.Add(lblNoiseW);
|
||||||
Controls.Add(trkNoiseW);
|
Controls.Add(trkNoiseW);
|
||||||
Controls.Add(lblNoiseWVal);
|
Controls.Add(lblNoiseWVal);
|
||||||
Controls.Add(lblTextInput);
|
|
||||||
Controls.Add(txtTextInput);
|
|
||||||
Controls.Add(txtLog);
|
Controls.Add(txtLog);
|
||||||
Controls.Add(chkMinimizeToTray);
|
Controls.Add(chkMinimizeToTray);
|
||||||
Controls.Add(btnClearLog);
|
Controls.Add(btnClearLog);
|
||||||
|
|||||||
+134
-134
@@ -17,10 +17,11 @@ internal sealed partial class MainForm : Form
|
|||||||
private LibPiperTtsEngine? _tts;
|
private LibPiperTtsEngine? _tts;
|
||||||
private AudioOutput? _audioOutput;
|
private AudioOutput? _audioOutput;
|
||||||
private TcpSttSource? _sttSource;
|
private TcpSttSource? _sttSource;
|
||||||
private Orchestrator? _orchestrator;
|
private VoicePipeline? _pipeline;
|
||||||
private PttHotkey? _pttHotkey;
|
private PttHotkey? _pttHotkey;
|
||||||
private NotifyIcon? _trayIcon;
|
private NotifyIcon? _trayIcon;
|
||||||
private bool _trayInit;
|
private bool _trayInit;
|
||||||
|
private bool _locked;
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
@@ -65,14 +66,11 @@ internal sealed partial class MainForm : Form
|
|||||||
chkMinimizeToTray.Checked = _config.MinimizeToTray;
|
chkMinimizeToTray.Checked = _config.MinimizeToTray;
|
||||||
txtSttEndpoint.Text = _config.SttEndpoint;
|
txtSttEndpoint.Text = _config.SttEndpoint;
|
||||||
|
|
||||||
btnBrowseFile.Click += OnBrowseFile;
|
|
||||||
btnTestVoice.Click += OnTestVoice;
|
|
||||||
btnManageVoices.Click += OnManageVoices;
|
btnManageVoices.Click += OnManageVoices;
|
||||||
btnClearLog.Click += (_, _) => txtLog.Clear();
|
btnClearLog.Click += (_, _) => txtLog.Clear();
|
||||||
|
btnLock.Click += OnLockToggle;
|
||||||
txtPttKey.Enter += OnPttKeyFocus;
|
txtPttKey.Enter += OnPttKeyFocus;
|
||||||
txtPttKey.KeyDown += OnPttKeyDown;
|
txtPttKey.KeyDown += OnPttKeyDown;
|
||||||
cmbOutput.SelectedIndexChanged += OnOutputChanged;
|
|
||||||
cmbVoice.SelectedIndexChanged += OnVoiceChanged;
|
|
||||||
txtSttEndpoint.Leave += OnSttEndpointChanged;
|
txtSttEndpoint.Leave += OnSttEndpointChanged;
|
||||||
|
|
||||||
trkNoise.Scroll += OnSliderScroll;
|
trkNoise.Scroll += OnSliderScroll;
|
||||||
@@ -90,10 +88,8 @@ internal sealed partial class MainForm : Form
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine($"OnLoad failed: {ex}");
|
Debug.WriteLine($"OnLoad failed: {ex}");
|
||||||
}
|
}
|
||||||
|
|
||||||
BeginInvoke(async () => await InitializeEngineAsync());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Keys _pttKey = Keys.F8;
|
private Keys _pttKey = Keys.F8;
|
||||||
@@ -216,7 +212,21 @@ internal sealed partial class MainForm : Form
|
|||||||
cmbOutput.SelectedIndex = 0;
|
cmbOutput.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task InitializeEngineAsync()
|
// ─── Lock / Release ────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
private async void OnLockToggle(object? sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (_locked)
|
||||||
|
{
|
||||||
|
ReleaseModel();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await LockModelAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task LockModelAsync()
|
||||||
{
|
{
|
||||||
if (cmbVoice.SelectedItem is not string voiceName)
|
if (cmbVoice.SelectedItem is not string voiceName)
|
||||||
{
|
{
|
||||||
@@ -237,43 +247,97 @@ internal sealed partial class MainForm : Form
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btnLock.Enabled = false;
|
||||||
Log($"Loading voice: {voiceName}...");
|
Log($"Loading voice: {voiceName}...");
|
||||||
_audioOutput?.Dispose();
|
|
||||||
if (_tts is not null)
|
|
||||||
await _tts.DisposeAsync();
|
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
_tts = new LibPiperTtsEngine(
|
_tts = new LibPiperTtsEngine(
|
||||||
modelPath,
|
modelPath,
|
||||||
_espeakDataPath,
|
_espeakDataPath,
|
||||||
noiseScale: trkNoise.Value / 1000.0f,
|
noiseScale: trkNoise.Value / 1000.0f,
|
||||||
lengthScale: trkSpeed.Value / 100.0f,
|
lengthScale: trkSpeed.Value / 100.0f,
|
||||||
noiseWScale: trkNoiseW.Value / 1000.0f);
|
noiseWScale: trkNoiseW.Value / 1000.0f);
|
||||||
|
|
||||||
|
await Task.Run(() => _tts.InitializeAsync());
|
||||||
|
Log($"TTS ready (sample rate: {_tts.SampleRate} Hz)");
|
||||||
|
|
||||||
_audioOutput = new AudioOutput();
|
_audioOutput = new AudioOutput();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (_sttSource is null)
|
|
||||||
{
|
|
||||||
_sttSource = new TcpSttSource { Endpoint = txtSttEndpoint.Text, Log = Log };
|
_sttSource = new TcpSttSource { Endpoint = txtSttEndpoint.Text, Log = Log };
|
||||||
|
_sttSource.TranscriptReceived += OnTranscript;
|
||||||
await _sttSource.StartAsync();
|
await _sttSource.StartAsync();
|
||||||
}
|
|
||||||
|
|
||||||
if (_orchestrator is not null)
|
_pipeline = new VoicePipeline(_tts, _audioOutput, Log)
|
||||||
await _orchestrator.DisposeAsync();
|
|
||||||
_orchestrator = new Orchestrator(_tts, _audioOutput, _sttSource, Log)
|
|
||||||
{
|
{
|
||||||
OutputDeviceName = cmbOutput.SelectedItem as string ?? string.Empty,
|
OutputDeviceName = cmbOutput.SelectedItem as string ?? string.Empty,
|
||||||
};
|
};
|
||||||
|
_pipeline.Start();
|
||||||
|
|
||||||
|
_locked = true;
|
||||||
|
SetControlsLocked(true);
|
||||||
|
btnLock.Text = "Release Model";
|
||||||
|
btnLock.Enabled = true;
|
||||||
|
|
||||||
await _orchestrator.InitializeTtsAsync();
|
|
||||||
Log("Engine ready. Press PTT to send to STT server.");
|
|
||||||
SetupHotkey();
|
SetupHotkey();
|
||||||
|
Log("Model locked. Press PTT to talk.");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log($"Init failed: {ex.Message}");
|
Log($"Lock failed: {ex.Message}");
|
||||||
|
btnLock.Enabled = true;
|
||||||
|
_tts?.DisposeAsync().AsTask().Wait();
|
||||||
|
_tts = null;
|
||||||
|
_audioOutput?.Dispose();
|
||||||
|
_audioOutput = null;
|
||||||
|
if (_sttSource is not null)
|
||||||
|
{
|
||||||
|
_sttSource.TranscriptReceived -= OnTranscript;
|
||||||
|
_sttSource.DisposeAsync().AsTask().Wait();
|
||||||
|
_sttSource = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReleaseModel()
|
||||||
|
{
|
||||||
|
if (!_locked) return;
|
||||||
|
|
||||||
|
_pttHotkey?.Dispose();
|
||||||
|
_pttHotkey = null;
|
||||||
|
|
||||||
|
if (_sttSource is not null)
|
||||||
|
{
|
||||||
|
_sttSource.TranscriptReceived -= OnTranscript;
|
||||||
|
_sttSource.DisposeAsync().AsTask().Wait();
|
||||||
|
_sttSource = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_pipeline?.Dispose();
|
||||||
|
_pipeline = null;
|
||||||
|
|
||||||
|
// VoicePipeline.Dispose calls _tts.DisposeAsync and _audioOutput.Dispose
|
||||||
|
_tts = null;
|
||||||
|
_audioOutput = null;
|
||||||
|
|
||||||
|
_locked = false;
|
||||||
|
SetControlsLocked(false);
|
||||||
|
btnLock.Text = "Lock Model";
|
||||||
|
Log("Model released.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetControlsLocked(bool locked)
|
||||||
|
{
|
||||||
|
cmbVoice.Enabled = !locked;
|
||||||
|
cmbOutput.Enabled = !locked;
|
||||||
|
trkNoise.Enabled = !locked;
|
||||||
|
trkSpeed.Enabled = !locked;
|
||||||
|
trkNoiseW.Enabled = !locked;
|
||||||
|
txtSttEndpoint.Enabled = !locked;
|
||||||
|
btnManageVoices.Enabled = !locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── PTT ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private void SetupHotkey()
|
private void SetupHotkey()
|
||||||
{
|
{
|
||||||
@@ -287,86 +351,56 @@ internal sealed partial class MainForm : Form
|
|||||||
|
|
||||||
private void OnPttPressed(object? sender, EventArgs e)
|
private void OnPttPressed(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Log("PTT pressed");
|
_pipeline?.OnPttPressed();
|
||||||
_orchestrator?.NotifyPttPressed();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_sttSource?.SendOn();
|
_sttSource?.SendOn();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Log($"SendOn failed: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnPttReleased(object? sender, EventArgs e)
|
private void OnPttReleased(object? sender, EventArgs e)
|
||||||
{
|
|
||||||
Log("PTT released");
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
_sttSource?.SendOff();
|
_sttSource?.SendOff();
|
||||||
|
_pipeline?.OnPttReleased();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
|
// ─── STT transcript → pipeline ──────────────────────────────────────────
|
||||||
|
|
||||||
|
private void OnTranscript(object? sender, TranscriptEventArgs e)
|
||||||
{
|
{
|
||||||
Log($"SendOff failed: {ex.Message}");
|
if (_pipeline is null || !_locked) return;
|
||||||
|
|
||||||
|
var msg = e.Message;
|
||||||
|
if (msg.Type == TranscriptType.Partial)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(msg.Text))
|
||||||
|
{
|
||||||
|
Log($"SEGMENT: \"{msg.Text}\"");
|
||||||
|
_pipeline.EnqueueSegment(msg.Text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(msg.Text))
|
||||||
|
{
|
||||||
|
Log($"FINAL: \"{msg.Text}\"");
|
||||||
|
_pipeline.EnqueueFinal(msg.Text);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log("FINAL: (empty)");
|
||||||
|
_pipeline.EnqueueFinal("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBrowseFile(object? sender, EventArgs e)
|
// ─── Voice manager ─────────────────────────────────────────────────────
|
||||||
{
|
|
||||||
using var dlg = new OpenFileDialog
|
|
||||||
{
|
|
||||||
Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*",
|
|
||||||
Title = "Select a text file to speak",
|
|
||||||
};
|
|
||||||
|
|
||||||
if (dlg.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
string text = File.ReadAllText(dlg.FileName);
|
|
||||||
lblFileName.Text = Path.GetFileName(dlg.FileName);
|
|
||||||
lblFileName.ForeColor = Color.Black;
|
|
||||||
Log($"Loaded: {dlg.FileName} ({text.Length} chars)");
|
|
||||||
_ = _orchestrator?.SynthesizeAsync(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTestVoice(object? sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (_orchestrator is null)
|
|
||||||
{
|
|
||||||
Log("Engine not initialized.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmbVoice.SelectedItem is not string voiceName)
|
|
||||||
{
|
|
||||||
Log("No voice selected.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!VoiceCatalogue.IsVoiceInstalled(_voicesDir, voiceName))
|
|
||||||
{
|
|
||||||
Log($"Voice '{voiceName}' is not installed. Use Add/Remove to download it.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
string text = txtTextInput.Text.Trim();
|
|
||||||
if (string.IsNullOrEmpty(text))
|
|
||||||
text = "Hello, this is a voice test.";
|
|
||||||
|
|
||||||
btnTestVoice.Enabled = false;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_ = _orchestrator.SynthesizeAsync(text);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
btnTestVoice.Enabled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnManageVoices(object? sender, EventArgs e)
|
private void OnManageVoices(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (_locked)
|
||||||
|
{
|
||||||
|
Log("Release the model before managing voices.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
string currentVoice = cmbVoice.SelectedItem as string ?? string.Empty;
|
string currentVoice = cmbVoice.SelectedItem as string ?? string.Empty;
|
||||||
using var dlg = new VoiceManagerForm(_voicesDir, currentVoice);
|
using var dlg = new VoiceManagerForm(_voicesDir, currentVoice);
|
||||||
dlg.ShowDialog(this);
|
dlg.ShowDialog(this);
|
||||||
@@ -384,31 +418,9 @@ internal sealed partial class MainForm : Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
_ = InitializeEngineAsync();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnVoiceChanged(object? sender, EventArgs e)
|
// ─── Slider / endpoint ─────────────────────────────────────────────────
|
||||||
{
|
|
||||||
btnTestVoice.Enabled = cmbVoice.SelectedItem is string voiceName
|
|
||||||
&& VoiceCatalogue.IsVoiceInstalled(_voicesDir, voiceName);
|
|
||||||
|
|
||||||
if (cmbVoice.SelectedItem is string name)
|
|
||||||
{
|
|
||||||
SaveConfig();
|
|
||||||
_ = ReinitializeEngineAsync(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task ReinitializeEngineAsync(string voiceName)
|
|
||||||
{
|
|
||||||
if (!VoiceCatalogue.IsVoiceInstalled(_voicesDir, voiceName))
|
|
||||||
{
|
|
||||||
btnTestVoice.Enabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await InitializeEngineAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnSliderScroll(object? sender, EventArgs e)
|
private void OnSliderScroll(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@@ -420,32 +432,15 @@ internal sealed partial class MainForm : Form
|
|||||||
private void OnSliderReleased(object? sender, MouseEventArgs e)
|
private void OnSliderReleased(object? sender, MouseEventArgs e)
|
||||||
{
|
{
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
if (cmbVoice.SelectedItem is string name && VoiceCatalogue.IsVoiceInstalled(_voicesDir, name))
|
|
||||||
{
|
|
||||||
_ = InitializeEngineAsync();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnOutputChanged(object? sender, EventArgs e)
|
private void OnSttEndpointChanged(object? sender, EventArgs e)
|
||||||
{
|
|
||||||
if (_orchestrator is not null)
|
|
||||||
_orchestrator.OutputDeviceName = cmbOutput.SelectedItem as string ?? string.Empty;
|
|
||||||
Log($"Output device: {_orchestrator?.OutputDeviceName}");
|
|
||||||
SaveConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void OnSttEndpointChanged(object? sender, EventArgs e)
|
|
||||||
{
|
{
|
||||||
_config.SttEndpoint = txtSttEndpoint.Text;
|
_config.SttEndpoint = txtSttEndpoint.Text;
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
if (_sttSource is not null)
|
// ─── Tray ──────────────────────────────────────────────────────────────
|
||||||
{
|
|
||||||
await _sttSource.DisposeAsync();
|
|
||||||
_sttSource = null;
|
|
||||||
await InitializeEngineAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetupTray()
|
private void SetupTray()
|
||||||
{
|
{
|
||||||
@@ -503,6 +498,8 @@ internal sealed partial class MainForm : Form
|
|||||||
Activate();
|
Activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── Config ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private void SaveConfig()
|
private void SaveConfig()
|
||||||
{
|
{
|
||||||
_config.Voice = cmbVoice.SelectedItem as string ?? string.Empty;
|
_config.Voice = cmbVoice.SelectedItem as string ?? string.Empty;
|
||||||
@@ -516,6 +513,8 @@ internal sealed partial class MainForm : Form
|
|||||||
_config.Save();
|
_config.Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── Logging ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private void Log(string message)
|
private void Log(string message)
|
||||||
{
|
{
|
||||||
if (IsDisposed) return;
|
if (IsDisposed) return;
|
||||||
@@ -530,12 +529,13 @@ internal sealed partial class MainForm : Form
|
|||||||
txtLog.ScrollToCaret();
|
txtLog.ScrollToCaret();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── Shutdown ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private void OnFormClosing(object? sender, FormClosingEventArgs e)
|
private void OnFormClosing(object? sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
_pttHotkey?.Dispose();
|
_pttHotkey?.Dispose();
|
||||||
_trayIcon!.Visible = false;
|
_trayIcon!.Visible = false;
|
||||||
_orchestrator?.DisposeAsync().AsTask().Wait(2000);
|
ReleaseModel();
|
||||||
_sttSource?.DisposeAsync().AsTask().Wait(2000);
|
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,257 +0,0 @@
|
|||||||
using Robovoice.Core;
|
|
||||||
using Robovoice.Tts.LibPiper;
|
|
||||||
|
|
||||||
namespace Robovoice.App;
|
|
||||||
|
|
||||||
internal sealed class Orchestrator : IAsyncDisposable
|
|
||||||
{
|
|
||||||
private readonly LibPiperTtsEngine _tts;
|
|
||||||
private readonly AudioOutput _audioOutput;
|
|
||||||
private readonly ISttSource _sttSource;
|
|
||||||
private readonly Action<string> _log;
|
|
||||||
private CancellationTokenSource? _currentCts;
|
|
||||||
private bool _disposed;
|
|
||||||
|
|
||||||
private readonly object _stateLock = new();
|
|
||||||
private readonly Queue<string> _pendingTexts = new();
|
|
||||||
private readonly List<float[]> _audioBuffer = new();
|
|
||||||
private int _bufferSampleRate;
|
|
||||||
private bool _playing;
|
|
||||||
private Task? _synthTask;
|
|
||||||
private CancellationTokenSource? _synthCts;
|
|
||||||
|
|
||||||
public string OutputDeviceName { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public Orchestrator(
|
|
||||||
LibPiperTtsEngine tts,
|
|
||||||
AudioOutput audioOutput,
|
|
||||||
ISttSource sttSource,
|
|
||||||
Action<string> log)
|
|
||||||
{
|
|
||||||
_tts = tts;
|
|
||||||
_audioOutput = audioOutput;
|
|
||||||
_audioOutput.Log = log;
|
|
||||||
_sttSource = sttSource;
|
|
||||||
_log = log;
|
|
||||||
_sttSource.TranscriptReceived += OnTranscript;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTranscript(object? sender, TranscriptEventArgs e)
|
|
||||||
{
|
|
||||||
var msg = e.Message;
|
|
||||||
|
|
||||||
lock (_stateLock)
|
|
||||||
{
|
|
||||||
if (msg.Type == TranscriptType.Partial)
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrWhiteSpace(msg.Text))
|
|
||||||
{
|
|
||||||
_log($"SEGMENT: \"{msg.Text}\" ({msg.Text.Length} chars)");
|
|
||||||
_pendingTexts.Enqueue(msg.Text);
|
|
||||||
EnsureSynthTask();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!string.IsNullOrWhiteSpace(msg.Text))
|
|
||||||
{
|
|
||||||
_log($"FINAL: \"{msg.Text}\" ({msg.Text.Length} chars)");
|
|
||||||
_pendingTexts.Enqueue(msg.Text);
|
|
||||||
EnsureSynthTask();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_log("FINAL: (empty)");
|
|
||||||
}
|
|
||||||
|
|
||||||
TransitionToPlaying();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TransitionToPlaying()
|
|
||||||
{
|
|
||||||
if (_playing)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (_audioBuffer.Count == 0)
|
|
||||||
{
|
|
||||||
if (_synthTask is null || _synthTask.IsCompleted)
|
|
||||||
{
|
|
||||||
_log("TTS: nothing to play");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_playing = true;
|
|
||||||
|
|
||||||
int sampleRate = _bufferSampleRate;
|
|
||||||
var chunks = _audioBuffer.ToList();
|
|
||||||
_audioBuffer.Clear();
|
|
||||||
|
|
||||||
_log($"TTS: playing {chunks.Count} buffered chunks ({sampleRate} Hz)");
|
|
||||||
|
|
||||||
_audioOutput.Start(sampleRate, OutputDeviceName);
|
|
||||||
foreach (var samples in chunks)
|
|
||||||
{
|
|
||||||
_audioOutput.WriteSamples(samples);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void EnsureSynthTask()
|
|
||||||
{
|
|
||||||
if (_synthTask is not null && !_synthTask.IsCompleted)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_synthCts?.Cancel();
|
|
||||||
_synthCts = new CancellationTokenSource();
|
|
||||||
_synthTask = SynthLoopAsync(_synthCts.Token);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task SynthLoopAsync(CancellationToken ct)
|
|
||||||
{
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
string text;
|
|
||||||
lock (_stateLock)
|
|
||||||
{
|
|
||||||
if (_pendingTexts.Count == 0)
|
|
||||||
break;
|
|
||||||
text = _pendingTexts.Dequeue();
|
|
||||||
}
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await foreach (var chunk in _tts.SynthesizeAsync(text, ct))
|
|
||||||
{
|
|
||||||
lock (_stateLock)
|
|
||||||
{
|
|
||||||
if (_playing)
|
|
||||||
{
|
|
||||||
_audioOutput.WriteSamples(chunk.Samples);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_bufferSampleRate = chunk.SampleRate;
|
|
||||||
_audioBuffer.Add(chunk.Samples);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (OperationCanceledException)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_log($"TTS error: {ex.Message}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lock (_stateLock)
|
|
||||||
{
|
|
||||||
if (_playing)
|
|
||||||
{
|
|
||||||
_audioOutput.Flush();
|
|
||||||
_log("TTS: synthesis complete, flushed");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void NotifyPttPressed()
|
|
||||||
{
|
|
||||||
lock (_stateLock)
|
|
||||||
{
|
|
||||||
_synthCts?.Cancel();
|
|
||||||
_synthCts?.Dispose();
|
|
||||||
_synthTask = null;
|
|
||||||
|
|
||||||
if (_playing)
|
|
||||||
{
|
|
||||||
_audioOutput.Stop();
|
|
||||||
_playing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_pendingTexts.Clear();
|
|
||||||
_audioBuffer.Clear();
|
|
||||||
_bufferSampleRate = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task InitializeTtsAsync()
|
|
||||||
{
|
|
||||||
_log("Initializing TTS engine...");
|
|
||||||
await Task.Run(() => _tts.InitializeAsync());
|
|
||||||
_log($"TTS ready (sample rate: {_tts.SampleRate} Hz)");
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SynthesizeAsync(string text)
|
|
||||||
{
|
|
||||||
_currentCts?.Cancel();
|
|
||||||
_currentCts = new CancellationTokenSource();
|
|
||||||
var ct = _currentCts.Token;
|
|
||||||
|
|
||||||
var sw = System.Diagnostics.Stopwatch.StartNew();
|
|
||||||
_log($"Speak: \"{text}\" ({text.Length} chars)");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bool started = false;
|
|
||||||
int chunkCount = 0;
|
|
||||||
int totalSamples = 0;
|
|
||||||
|
|
||||||
await foreach (var chunk in _tts.SynthesizeAsync(text, ct))
|
|
||||||
{
|
|
||||||
if (!started)
|
|
||||||
{
|
|
||||||
started = true;
|
|
||||||
_audioOutput.Start(chunk.SampleRate, OutputDeviceName);
|
|
||||||
_log($"TTS: first chunk ({sw.ElapsedMilliseconds}ms)");
|
|
||||||
}
|
|
||||||
|
|
||||||
_audioOutput.WriteSamples(chunk.Samples);
|
|
||||||
chunkCount++;
|
|
||||||
totalSamples += chunk.Samples.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!started)
|
|
||||||
{
|
|
||||||
_log("TTS: no audio produced");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_audioOutput.Flush();
|
|
||||||
double durationSec = (double)totalSamples / _tts.SampleRate;
|
|
||||||
_log($"TTS: done ({chunkCount} chunks, {durationSec:F2}s audio, {sw.ElapsedMilliseconds}ms)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (OperationCanceledException)
|
|
||||||
{
|
|
||||||
_log("TTS: cancelled");
|
|
||||||
_audioOutput.Stop();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_log($"TTS error: {ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
sw.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
|
||||||
{
|
|
||||||
if (_disposed) return;
|
|
||||||
_disposed = true;
|
|
||||||
|
|
||||||
try { _currentCts?.Cancel(); } catch { }
|
|
||||||
_currentCts?.Dispose();
|
|
||||||
|
|
||||||
try { _synthCts?.Cancel(); } catch { }
|
|
||||||
_synthCts?.Dispose();
|
|
||||||
|
|
||||||
_sttSource.TranscriptReceived -= OnTranscript;
|
|
||||||
await _sttSource.DisposeAsync();
|
|
||||||
await _tts.DisposeAsync();
|
|
||||||
_audioOutput.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
using System.Collections.Concurrent;
|
||||||
|
using Robovoice.Core;
|
||||||
|
using Robovoice.Tts.LibPiper;
|
||||||
|
|
||||||
|
namespace Robovoice.App;
|
||||||
|
|
||||||
|
internal sealed record TextItem(uint Session, string Text);
|
||||||
|
|
||||||
|
internal sealed record AudioItem(uint Session, float[]? Samples);
|
||||||
|
|
||||||
|
internal sealed class VoicePipeline : IDisposable
|
||||||
|
{
|
||||||
|
private readonly LibPiperTtsEngine _tts;
|
||||||
|
private readonly AudioOutput _audioOutput;
|
||||||
|
private readonly Action<string> _log;
|
||||||
|
|
||||||
|
private BlockingCollection<TextItem> _textQueue = new();
|
||||||
|
private BlockingCollection<AudioItem> _audioQueue = new();
|
||||||
|
private ManualResetEventSlim _gate = new(false);
|
||||||
|
private volatile uint _currentSession;
|
||||||
|
private volatile bool _running;
|
||||||
|
|
||||||
|
private Thread? _synthThread;
|
||||||
|
private Thread? _playerThread;
|
||||||
|
private bool _disposed;
|
||||||
|
|
||||||
|
public string OutputDeviceName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public VoicePipeline(
|
||||||
|
LibPiperTtsEngine tts,
|
||||||
|
AudioOutput audioOutput,
|
||||||
|
Action<string> log)
|
||||||
|
{
|
||||||
|
_tts = tts;
|
||||||
|
_audioOutput = audioOutput;
|
||||||
|
_audioOutput.Log = log;
|
||||||
|
_log = log;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Start()
|
||||||
|
{
|
||||||
|
_running = true;
|
||||||
|
_synthThread = new Thread(SynthLoop) { IsBackground = true, Name = "VoicePipeline-Synth" };
|
||||||
|
_playerThread = new Thread(PlayerLoop) { IsBackground = true, Name = "VoicePipeline-Player" };
|
||||||
|
_synthThread.Start();
|
||||||
|
_playerThread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EnqueueSegment(string text)
|
||||||
|
{
|
||||||
|
if (!_running) return;
|
||||||
|
uint session = _currentSession;
|
||||||
|
_textQueue.Add(new TextItem(session, text));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void EnqueueFinal(string text)
|
||||||
|
{
|
||||||
|
if (!_running) return;
|
||||||
|
uint session = _currentSession;
|
||||||
|
if (!string.IsNullOrEmpty(text))
|
||||||
|
_textQueue.Add(new TextItem(session, text));
|
||||||
|
_textQueue.Add(new TextItem(session, ""));
|
||||||
|
_gate.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPttPressed()
|
||||||
|
{
|
||||||
|
_currentSession++;
|
||||||
|
_gate.Reset();
|
||||||
|
_audioOutput.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnPttReleased()
|
||||||
|
{
|
||||||
|
_gate.Set();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SynthLoop()
|
||||||
|
{
|
||||||
|
foreach (var item in _textQueue.GetConsumingEnumerable())
|
||||||
|
{
|
||||||
|
if (!_running) break;
|
||||||
|
|
||||||
|
if (item.Session != _currentSession)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (item.Text.Length == 0)
|
||||||
|
{
|
||||||
|
// :F sentinel — signal end of utterance to player
|
||||||
|
_audioQueue.Add(new AudioItem(item.Session, null));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var chunk in _tts.SynthesizeSync(item.Text))
|
||||||
|
{
|
||||||
|
if (item.Session != _currentSession)
|
||||||
|
{
|
||||||
|
// Session changed mid-synthesis — drain piper cleanly
|
||||||
|
_tts.SynthesizeDrain();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_audioQueue.Add(new AudioItem(item.Session, chunk.Samples));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_log($"TTS error: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void PlayerLoop()
|
||||||
|
{
|
||||||
|
while (_running)
|
||||||
|
{
|
||||||
|
_gate.Wait();
|
||||||
|
if (!_running) break;
|
||||||
|
|
||||||
|
// Drain stale items, then wait for real audio for current session
|
||||||
|
AudioItem firstItem = default!;
|
||||||
|
while (_running)
|
||||||
|
{
|
||||||
|
try { firstItem = _audioQueue.Take(); }
|
||||||
|
catch (InvalidOperationException) { return; }
|
||||||
|
|
||||||
|
if (firstItem.Session != _currentSession)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_running) break;
|
||||||
|
|
||||||
|
if (firstItem.Samples == null)
|
||||||
|
{
|
||||||
|
// :F with no audio — nothing to play
|
||||||
|
_gate.Reset();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
_audioOutput.Start(_tts.SampleRate, OutputDeviceName);
|
||||||
|
_audioOutput.WriteSamples(firstItem.Samples);
|
||||||
|
_log($"TTS: playback started (session {firstItem.Session})");
|
||||||
|
|
||||||
|
foreach (var item in _audioQueue.GetConsumingEnumerable())
|
||||||
|
{
|
||||||
|
if (!_running) break;
|
||||||
|
|
||||||
|
if (item.Session != _currentSession)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (item.Samples == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
_audioOutput.WriteSamples(item.Samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
_audioOutput.Flush();
|
||||||
|
_log("TTS: playback finished");
|
||||||
|
_gate.Reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
if (_disposed) return;
|
||||||
|
_disposed = true;
|
||||||
|
_running = false;
|
||||||
|
|
||||||
|
_gate.Set();
|
||||||
|
_textQueue.CompleteAdding();
|
||||||
|
_audioQueue.CompleteAdding();
|
||||||
|
|
||||||
|
_synthThread?.Join(5000);
|
||||||
|
_playerThread?.Join(5000);
|
||||||
|
|
||||||
|
_textQueue.Dispose();
|
||||||
|
_audioQueue.Dispose();
|
||||||
|
_gate.Dispose();
|
||||||
|
|
||||||
|
_tts.DisposeAsync().AsTask().Wait();
|
||||||
|
_audioOutput.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,10 +9,9 @@ public sealed class TcpSttSource : ISttSource
|
|||||||
{
|
{
|
||||||
private TcpClient? _tcp;
|
private TcpClient? _tcp;
|
||||||
private NetworkStream? _stream;
|
private NetworkStream? _stream;
|
||||||
private StreamReader? _reader;
|
|
||||||
private StreamWriter? _writer;
|
private StreamWriter? _writer;
|
||||||
private CancellationTokenSource? _cts;
|
private Thread? _connectThread;
|
||||||
private Task? _runTask;
|
private volatile bool _running;
|
||||||
private readonly object _sendLock = new();
|
private readonly object _sendLock = new();
|
||||||
private uint _session;
|
private uint _session;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
@@ -26,107 +25,157 @@ public sealed class TcpSttSource : ISttSource
|
|||||||
public Task StartAsync(CancellationToken ct = default)
|
public Task StartAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||||
if (_cts is not null)
|
if (_running)
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
||||||
_cts = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
_running = true;
|
||||||
_runTask = RunAsync(_cts.Token);
|
_connectThread = new Thread(ConnectLoop) { IsBackground = true, Name = "TcpSttSource-Connect" };
|
||||||
|
_connectThread.Start();
|
||||||
|
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StopAsync(CancellationToken ct = default)
|
public Task StopAsync(CancellationToken ct = default)
|
||||||
{
|
{
|
||||||
if (_cts is not null)
|
_running = false;
|
||||||
_cts.Cancel();
|
|
||||||
|
|
||||||
CleanupConnection();
|
lock (_sendLock)
|
||||||
|
|
||||||
if (_runTask is not null)
|
|
||||||
{
|
{
|
||||||
try { await _runTask.WaitAsync(ct); }
|
_writer?.Dispose();
|
||||||
catch { }
|
_stream?.Dispose();
|
||||||
_runTask = null;
|
_tcp?.Close();
|
||||||
|
_writer = null;
|
||||||
|
_stream = null;
|
||||||
|
_tcp = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_cts?.Dispose();
|
// Threads are background — they'll die when the process exits.
|
||||||
_cts = null;
|
// Closing the socket unblocks any pending Read.
|
||||||
|
_connectThread?.Join(1000);
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RunAsync(CancellationToken ct)
|
private void ConnectLoop()
|
||||||
{
|
{
|
||||||
while (!ct.IsCancellationRequested)
|
while (_running)
|
||||||
{
|
{
|
||||||
IPEndPoint? endpoint = ParseEndpoint(Endpoint);
|
IPEndPoint? endpoint = ParseEndpoint(Endpoint);
|
||||||
if (endpoint is null)
|
if (endpoint is null)
|
||||||
{
|
{
|
||||||
Log?.Invoke($"STT: invalid endpoint '{Endpoint}'");
|
Log?.Invoke($"STT: invalid endpoint '{Endpoint}'");
|
||||||
try { await Task.Delay(3000, ct); } catch { break; }
|
SleepInterruptible(3000);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_tcp = new TcpClient();
|
var tcp = new TcpClient();
|
||||||
using var connectCts = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
tcp.Connect(endpoint.Address, endpoint.Port);
|
||||||
connectCts.CancelAfter(TimeSpan.FromSeconds(5));
|
tcp.NoDelay = true;
|
||||||
await _tcp.ConnectAsync(endpoint.Address, endpoint.Port, connectCts.Token);
|
|
||||||
|
|
||||||
_stream = _tcp.GetStream();
|
lock (_sendLock)
|
||||||
_reader = new StreamReader(_stream, Encoding.UTF8);
|
{
|
||||||
_writer = new StreamWriter(_stream, Encoding.UTF8) { AutoFlush = true };
|
_tcp = tcp;
|
||||||
|
_stream = tcp.GetStream();
|
||||||
|
_writer = new StreamWriter(_stream, new UTF8Encoding(false)) { AutoFlush = true };
|
||||||
|
}
|
||||||
|
|
||||||
Log?.Invoke($"STT: connected to {Endpoint}");
|
Log?.Invoke($"STT: connected to {Endpoint}");
|
||||||
|
|
||||||
await ReceiveLoopAsync(ct);
|
// Blocking receive loop — runs until disconnected or stopped.
|
||||||
}
|
ReceiveLoop();
|
||||||
catch (OperationCanceledException)
|
|
||||||
{
|
Log?.Invoke("STT: disconnected");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
if (_running)
|
||||||
Log?.Invoke($"STT: connection failed ({ex.Message}), retrying...");
|
Log?.Invoke($"STT: connection failed ({ex.Message}), retrying...");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
CleanupConnection();
|
lock (_sendLock)
|
||||||
}
|
|
||||||
|
|
||||||
if (!ct.IsCancellationRequested)
|
|
||||||
{
|
{
|
||||||
try { await Task.Delay(3000, ct); }
|
_writer?.Dispose();
|
||||||
catch (OperationCanceledException) { break; }
|
_stream?.Dispose();
|
||||||
}
|
_tcp?.Close();
|
||||||
|
_writer = null;
|
||||||
|
_stream = null;
|
||||||
|
_tcp = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ReceiveLoopAsync(CancellationToken ct)
|
if (_running)
|
||||||
|
SleepInterruptible(3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReceiveLoop()
|
||||||
{
|
{
|
||||||
while (!ct.IsCancellationRequested && _reader is not null)
|
byte[] buffer = new byte[4096];
|
||||||
|
StringBuilder lineBuf = new();
|
||||||
|
|
||||||
|
while (_running)
|
||||||
{
|
{
|
||||||
string? line;
|
NetworkStream? stream;
|
||||||
|
lock (_sendLock)
|
||||||
|
{
|
||||||
|
stream = _stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stream is null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
int bytesRead;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
line = await _reader.ReadLineAsync(ct);
|
bytesRead = stream.Read(buffer, 0, buffer.Length);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line is null)
|
if (bytesRead == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
TranscriptMessage? message = ParseReply(line);
|
for (int i = 0; i < bytesRead; i++)
|
||||||
if (message is null)
|
{
|
||||||
continue;
|
byte b = buffer[i];
|
||||||
|
if (b == '\n')
|
||||||
|
{
|
||||||
|
string line = lineBuf.ToString().TrimEnd('\r');
|
||||||
|
lineBuf.Clear();
|
||||||
|
|
||||||
|
TranscriptMessage? message = ParseReply(line);
|
||||||
|
if (message is not null)
|
||||||
|
{
|
||||||
TranscriptReceived?.Invoke(this, new TranscriptEventArgs
|
TranscriptReceived?.Invoke(this, new TranscriptEventArgs
|
||||||
{
|
{
|
||||||
Message = message,
|
Message = message,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lineBuf.Append((char)b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SleepInterruptible(int ms)
|
||||||
|
{
|
||||||
|
int slice = 100;
|
||||||
|
int waited = 0;
|
||||||
|
while (_running && waited < ms)
|
||||||
|
{
|
||||||
|
int chunk = Math.Min(slice, ms - waited);
|
||||||
|
Thread.Sleep(chunk);
|
||||||
|
waited += chunk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SendOn()
|
public void SendOn()
|
||||||
{
|
{
|
||||||
@@ -157,21 +206,6 @@ public sealed class TcpSttSource : ISttSource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CleanupConnection()
|
|
||||||
{
|
|
||||||
lock (_sendLock)
|
|
||||||
{
|
|
||||||
_writer?.Dispose();
|
|
||||||
_reader?.Dispose();
|
|
||||||
_stream?.Dispose();
|
|
||||||
_tcp?.Dispose();
|
|
||||||
_writer = null;
|
|
||||||
_reader = null;
|
|
||||||
_stream = null;
|
|
||||||
_tcp = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IPEndPoint? ParseEndpoint(string endpoint)
|
private static IPEndPoint? ParseEndpoint(string endpoint)
|
||||||
{
|
{
|
||||||
int colon = endpoint.LastIndexOf(':');
|
int colon = endpoint.LastIndexOf(':');
|
||||||
@@ -224,33 +258,34 @@ public sealed class TcpSttSource : ISttSource
|
|||||||
{
|
{
|
||||||
string rest = line["F ".Length..];
|
string rest = line["F ".Length..];
|
||||||
int space = rest.IndexOf(' ');
|
int space = rest.IndexOf(' ');
|
||||||
|
|
||||||
if (space < 0)
|
if (space < 0)
|
||||||
return null;
|
|
||||||
|
|
||||||
if (!uint.TryParse(rest[..space], out uint session))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (session != _session)
|
|
||||||
{
|
{
|
||||||
Log?.Invoke($"STT: dropping stale reply (session {session} != current {_session})");
|
if (uint.TryParse(rest, out uint session) && session == _session)
|
||||||
|
return new TranscriptMessage(TranscriptType.Final, string.Empty);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!uint.TryParse(rest[..space], out uint ses))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (ses != _session)
|
||||||
|
{
|
||||||
|
Log?.Invoke($"STT: dropping stale reply (session {ses} != current {_session})");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TranscriptMessage(TranscriptType.Final, rest[(space + 1)..]);
|
return new TranscriptMessage(TranscriptType.Final, rest[(space + 1)..]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line == "F")
|
|
||||||
{
|
|
||||||
return new TranscriptMessage(TranscriptType.Final, string.Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async ValueTask DisposeAsync()
|
public ValueTask DisposeAsync()
|
||||||
{
|
{
|
||||||
if (_disposed) return;
|
if (_disposed) return ValueTask.CompletedTask;
|
||||||
await StopAsync();
|
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
|
StopAsync();
|
||||||
|
return ValueTask.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,6 +120,71 @@ public sealed class LibPiperTtsEngine : ITtsEngine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<AudioChunk> SynthesizeSync(string text)
|
||||||
|
{
|
||||||
|
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||||
|
if (!_initialized)
|
||||||
|
throw new InvalidOperationException("Engine not initialized.");
|
||||||
|
|
||||||
|
var options = new PiperSynthesizeOptions
|
||||||
|
{
|
||||||
|
SpeakerId = 0,
|
||||||
|
LengthScale = _lengthScale,
|
||||||
|
NoiseScale = _noiseScale,
|
||||||
|
NoiseWScale = _noiseWScale,
|
||||||
|
};
|
||||||
|
|
||||||
|
byte[] textBytes = System.Text.Encoding.UTF8.GetBytes(EnsureTerminator(text) + "\0");
|
||||||
|
GCHandle textPin = GCHandle.Alloc(textBytes, GCHandleType.Pinned);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int startResult = PiperNative.piper_synthesize_start(
|
||||||
|
_synth, textPin.AddrOfPinnedObject(), in options);
|
||||||
|
if (startResult != PiperNative.PiperOk)
|
||||||
|
throw new InvalidOperationException($"piper_synthesize_start failed: {startResult}");
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
PiperAudioChunk chunk = default;
|
||||||
|
int result = PiperNative.piper_synthesize_next(_synth, out chunk);
|
||||||
|
|
||||||
|
if (chunk.NumSamples > 0 && chunk.Samples != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
int numSamples = (int)chunk.NumSamples;
|
||||||
|
float[] samples = new float[numSamples];
|
||||||
|
Marshal.Copy(chunk.Samples, samples, 0, numSamples);
|
||||||
|
|
||||||
|
if (chunk.SampleRate > 0)
|
||||||
|
_sampleRate = chunk.SampleRate;
|
||||||
|
|
||||||
|
yield return new AudioChunk(samples, _sampleRate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result == PiperNative.PiperDone || chunk.IsLast)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (result < 0)
|
||||||
|
throw new InvalidOperationException($"piper_synthesize_next failed: {result}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
textPin.Free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SynthesizeDrain()
|
||||||
|
{
|
||||||
|
if (!_initialized || _synth == IntPtr.Zero)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PiperAudioChunk chunk;
|
||||||
|
while (PiperNative.piper_synthesize_next(_synth, out chunk) != PiperNative.PiperDone)
|
||||||
|
{
|
||||||
|
if (chunk.IsLast) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static string EnsureTerminator(string text)
|
private static string EnsureTerminator(string text)
|
||||||
{
|
{
|
||||||
string trimmed = text.TrimEnd();
|
string trimmed = text.TrimEnd();
|
||||||
|
|||||||
+241
-47
@@ -8,6 +8,7 @@ use std::io::{BufRead, BufReader, Write};
|
|||||||
use std::net::{TcpListener, TcpStream};
|
use std::net::{TcpListener, TcpStream};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
use std::sync::mpsc;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
@@ -69,12 +70,112 @@ fn line_text(line: &transcript_line_t) -> String {
|
|||||||
.into_owned()
|
.into_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn unix_now() -> u64 {
|
||||||
|
SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.unwrap_or_default()
|
||||||
|
.as_secs()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── debug session recorder ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
struct DebugRecorder {
|
||||||
|
dir: PathBuf,
|
||||||
|
audio: Vec<f32>,
|
||||||
|
log_lines: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DebugRecorder {
|
||||||
|
fn new(base_dir: &PathBuf) -> Self {
|
||||||
|
let dir = base_dir.join(unix_now().to_string());
|
||||||
|
std::fs::create_dir_all(&dir).ok();
|
||||||
|
Self {
|
||||||
|
dir,
|
||||||
|
audio: Vec::new(),
|
||||||
|
log_lines: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_event(&mut self, event: &str) {
|
||||||
|
self.log_lines.push(format!("[{}] {}", ts(), event));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_segment(&mut self, line: &transcript_line_t, prefix: &str) {
|
||||||
|
let text = line_text(line);
|
||||||
|
let event = format!(
|
||||||
|
"SEGMENT id={} prefix={} is_complete={} start={:.3}s duration={:.3}s text=\"{}\"",
|
||||||
|
line.id, prefix, line.is_complete, line.start_time, line.duration, text
|
||||||
|
);
|
||||||
|
self.log_event(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_audio(&mut self, samples: &[f32]) {
|
||||||
|
self.audio.extend_from_slice(samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save(self) {
|
||||||
|
// Write log
|
||||||
|
let log_path = self.dir.join("session.log");
|
||||||
|
match std::fs::File::create(&log_path) {
|
||||||
|
Ok(mut f) => {
|
||||||
|
for line in &self.log_lines {
|
||||||
|
writeln!(f, "{}", line).ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => log(&format!("debug: failed to write log: {}", e)),
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write WAV
|
||||||
|
let wav_path = self.dir.join("audio.wav");
|
||||||
|
match write_wav(&wav_path, &self.audio, SAMPLE_RATE as u32) {
|
||||||
|
Ok(()) => {
|
||||||
|
let secs = self.audio.len() as f64 / SAMPLE_RATE as f64;
|
||||||
|
log(&format!("debug: saved {} ({:.1}s, {} samples)", self.dir.display(), secs, self.audio.len()));
|
||||||
|
}
|
||||||
|
Err(e) => log(&format!("debug: failed to write wav: {}", e)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_wav(path: &PathBuf, samples: &[f32], sample_rate: u32) -> Result<()> {
|
||||||
|
let num_samples = samples.len() as u32;
|
||||||
|
let data_size = num_samples * 4; // f32 = 4 bytes
|
||||||
|
let file_size = 44 + data_size;
|
||||||
|
|
||||||
|
let mut f = std::fs::File::create(path)?;
|
||||||
|
// RIFF header
|
||||||
|
f.write_all(b"RIFF")?;
|
||||||
|
f.write_all(&(file_size - 8).to_le_bytes())?;
|
||||||
|
f.write_all(b"WAVE")?;
|
||||||
|
// fmt chunk
|
||||||
|
f.write_all(b"fmt ")?;
|
||||||
|
f.write_all(&16u32.to_le_bytes())?; // chunk size
|
||||||
|
f.write_all(&3u16.to_le_bytes())?; // IEEE float
|
||||||
|
f.write_all(&1u16.to_le_bytes())?; // mono
|
||||||
|
f.write_all(&sample_rate.to_le_bytes())?;
|
||||||
|
f.write_all(&(sample_rate * 4).to_le_bytes())?; // byte rate
|
||||||
|
f.write_all(&4u16.to_le_bytes())?; // block align
|
||||||
|
f.write_all(&32u16.to_le_bytes())?; // bits per sample
|
||||||
|
// data chunk
|
||||||
|
f.write_all(b"data")?;
|
||||||
|
f.write_all(&data_size.to_le_bytes())?;
|
||||||
|
|
||||||
|
// Convert f32 samples to little-endian bytes
|
||||||
|
let mut bytes = Vec::with_capacity(data_size as usize);
|
||||||
|
for &s in samples {
|
||||||
|
bytes.extend_from_slice(&s.to_le_bytes());
|
||||||
|
}
|
||||||
|
f.write_all(&bytes)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
// ─── shared state ─────────────────────────────────────────────────────────
|
// ─── shared state ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
struct Shared {
|
struct Shared {
|
||||||
writer: Mutex<TcpStream>,
|
writer: Mutex<TcpStream>,
|
||||||
session_id: u64,
|
session_id: u64,
|
||||||
transcriber_handle: i32,
|
transcriber_handle: i32,
|
||||||
|
debug_dir: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Shared {
|
impl Shared {
|
||||||
@@ -100,23 +201,26 @@ struct Session {
|
|||||||
stop_signal: Arc<AtomicBool>,
|
stop_signal: Arc<AtomicBool>,
|
||||||
aborted: Arc<AtomicBool>,
|
aborted: Arc<AtomicBool>,
|
||||||
transcriber: thread::JoinHandle<()>,
|
transcriber: thread::JoinHandle<()>,
|
||||||
cpal_stream: cpal::Stream,
|
cpal_stream: Option<cpal::Stream>,
|
||||||
stream_handle: i32,
|
stream_handle: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
fn stop(self) {
|
fn stop(mut self) {
|
||||||
|
// Signal transcriber to exit main loop, then wait for it to drain
|
||||||
|
// trailing audio + final flush. cpal stream stays alive during drain.
|
||||||
self.stop_signal.store(true, Ordering::SeqCst);
|
self.stop_signal.store(true, Ordering::SeqCst);
|
||||||
drop(self.cpal_stream);
|
|
||||||
self.transcriber.join().ok();
|
self.transcriber.join().ok();
|
||||||
|
// Now safe to kill ALSA — transcriber is done
|
||||||
|
self.cpal_stream.take();
|
||||||
unsafe { moonshine_free_stream(self.shared.transcriber_handle, self.stream_handle) };
|
unsafe { moonshine_free_stream(self.shared.transcriber_handle, self.stream_handle) };
|
||||||
}
|
}
|
||||||
|
|
||||||
fn abort(self) {
|
fn abort(mut self) {
|
||||||
self.stop_signal.store(true, Ordering::SeqCst);
|
|
||||||
self.aborted.store(true, Ordering::SeqCst);
|
self.aborted.store(true, Ordering::SeqCst);
|
||||||
drop(self.cpal_stream);
|
self.stop_signal.store(true, Ordering::SeqCst);
|
||||||
self.transcriber.join().ok();
|
self.transcriber.join().ok();
|
||||||
|
self.cpal_stream.take();
|
||||||
unsafe { moonshine_free_stream(self.shared.transcriber_handle, self.stream_handle) };
|
unsafe { moonshine_free_stream(self.shared.transcriber_handle, self.stream_handle) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,12 +238,12 @@ fn start_session(shared: Arc<Shared>) -> Option<Session> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let audio_buf: Arc<Mutex<Vec<f32>>> = Arc::new(Mutex::new(Vec::new()));
|
let (tx, rx) = mpsc::channel::<Vec<f32>>();
|
||||||
let stop_signal = Arc::new(AtomicBool::new(false));
|
let stop_signal = Arc::new(AtomicBool::new(false));
|
||||||
let aborted = Arc::new(AtomicBool::new(false));
|
let aborted = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let cpal_stream = match start_cpal(audio_buf.clone(), stop_signal.clone()) {
|
let cpal_stream = match start_cpal(tx) {
|
||||||
Ok(s) => s,
|
Ok(s) => Some(s),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log(&format!("cpal failed: {}", e));
|
log(&format!("cpal failed: {}", e));
|
||||||
unsafe { moonshine_free_stream(shared.transcriber_handle, stream_handle) };
|
unsafe { moonshine_free_stream(shared.transcriber_handle, stream_handle) };
|
||||||
@@ -152,7 +256,7 @@ fn start_session(shared: Arc<Shared>) -> Option<Session> {
|
|||||||
let aborted_clone = aborted.clone();
|
let aborted_clone = aborted.clone();
|
||||||
|
|
||||||
let transcriber = thread::spawn(move || {
|
let transcriber = thread::spawn(move || {
|
||||||
transcriber_loop(shared_clone, audio_buf, stop_signal_clone, aborted_clone, stream_handle);
|
transcriber_loop(shared_clone, rx, stop_signal_clone, aborted_clone, stream_handle);
|
||||||
});
|
});
|
||||||
|
|
||||||
Some(Session {
|
Some(Session {
|
||||||
@@ -167,7 +271,7 @@ fn start_session(shared: Arc<Shared>) -> Option<Session> {
|
|||||||
|
|
||||||
fn transcriber_loop(
|
fn transcriber_loop(
|
||||||
shared: Arc<Shared>,
|
shared: Arc<Shared>,
|
||||||
audio_buf: Arc<Mutex<Vec<f32>>>,
|
rx: mpsc::Receiver<Vec<f32>>,
|
||||||
stop_signal: Arc<AtomicBool>,
|
stop_signal: Arc<AtomicBool>,
|
||||||
aborted: Arc<AtomicBool>,
|
aborted: Arc<AtomicBool>,
|
||||||
stream_handle: i32,
|
stream_handle: i32,
|
||||||
@@ -175,16 +279,22 @@ fn transcriber_loop(
|
|||||||
let handle = shared.transcriber_handle;
|
let handle = shared.transcriber_handle;
|
||||||
let mut sent_ids: HashSet<u64> = HashSet::new();
|
let mut sent_ids: HashSet<u64> = HashSet::new();
|
||||||
|
|
||||||
while !stop_signal.load(Ordering::SeqCst) {
|
// Debug recorder (if enabled)
|
||||||
let chunk = {
|
let mut recorder = shared.debug_dir.as_ref().map(|_| DebugRecorder::new(
|
||||||
let mut buf = audio_buf.lock().unwrap();
|
&shared.debug_dir.as_ref().unwrap().join(shared.session_id.to_string()),
|
||||||
if buf.is_empty() {
|
));
|
||||||
drop(buf);
|
|
||||||
thread::sleep(Duration::from_millis(5));
|
if let Some(ref mut r) = recorder {
|
||||||
continue;
|
r.log_event(&format!("session {} started", shared.session_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main loop: process audio until stop_signal
|
||||||
|
while !stop_signal.load(Ordering::SeqCst) {
|
||||||
|
match rx.recv_timeout(Duration::from_millis(100)) {
|
||||||
|
Ok(chunk) => {
|
||||||
|
if let Some(ref mut r) = recorder {
|
||||||
|
r.add_audio(&chunk);
|
||||||
}
|
}
|
||||||
std::mem::take(&mut *buf)
|
|
||||||
};
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
moonshine_transcribe_add_audio_to_stream(
|
moonshine_transcribe_add_audio_to_stream(
|
||||||
@@ -200,31 +310,80 @@ fn transcriber_loop(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(ref mut r) = recorder {
|
||||||
|
log_transcript_lines(r, t_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
send_new_segments(&shared, t_ptr, &mut sent_ids, "P");
|
send_new_segments(&shared, t_ptr, &mut sent_ids, "P");
|
||||||
}
|
}
|
||||||
|
Err(mpsc::RecvTimeoutError::Timeout) => continue,
|
||||||
|
Err(mpsc::RecvTimeoutError::Disconnected) => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Drain trailing audio from ALSA buffer (cpal stream still alive).
|
||||||
|
// Fixed 100ms window — cpal delivers every ~50ms (800 samples @ 16kHz),
|
||||||
|
// so this captures 1-2 more callbacks worth of trailing audio.
|
||||||
|
// Hold one chunk back so we can apply a fade-out to the very last one.
|
||||||
|
let drain_deadline = std::time::Instant::now() + Duration::from_millis(100);
|
||||||
|
let mut held_chunk: Option<Vec<f32>> = None;
|
||||||
|
while std::time::Instant::now() < drain_deadline {
|
||||||
|
match rx.recv_timeout(drain_deadline - std::time::Instant::now()) {
|
||||||
|
Ok(chunk) => {
|
||||||
|
// Feed previously held chunk to Moonshine + recorder (no fade)
|
||||||
|
if let Some(prev) = held_chunk.take() {
|
||||||
|
if let Some(ref mut r) = recorder {
|
||||||
|
r.add_audio(&prev);
|
||||||
|
}
|
||||||
|
unsafe {
|
||||||
|
moonshine_transcribe_add_audio_to_stream(
|
||||||
|
handle, stream_handle,
|
||||||
|
prev.as_ptr(), prev.len() as u64,
|
||||||
|
SAMPLE_RATE, 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
held_chunk = Some(chunk);
|
||||||
|
}
|
||||||
|
Err(mpsc::RecvTimeoutError::Timeout) => break,
|
||||||
|
Err(mpsc::RecvTimeoutError::Disconnected) => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply 5ms fade-out to the last chunk, then feed to both Moonshine and recorder
|
||||||
|
if let Some(mut chunk) = held_chunk.take() {
|
||||||
|
let fade_samples = (SAMPLE_RATE as usize * 25) / 1000; // 25ms
|
||||||
|
if chunk.len() > fade_samples {
|
||||||
|
let start = chunk.len() - fade_samples;
|
||||||
|
for i in 0..fade_samples {
|
||||||
|
let t = 1.0 - (i as f32 / fade_samples as f32);
|
||||||
|
chunk[start + i] *= t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(ref mut r) = recorder {
|
||||||
|
r.add_audio(&chunk);
|
||||||
|
}
|
||||||
|
unsafe {
|
||||||
|
moonshine_transcribe_add_audio_to_stream(
|
||||||
|
handle, stream_handle,
|
||||||
|
chunk.as_ptr(), chunk.len() as u64,
|
||||||
|
SAMPLE_RATE, 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If aborted (new session took over), skip final flush entirely
|
// If aborted (new session took over), skip final flush entirely
|
||||||
if aborted.load(Ordering::SeqCst) {
|
if aborted.load(Ordering::SeqCst) {
|
||||||
unsafe { moonshine_stop_stream(handle, stream_handle) };
|
unsafe { moonshine_stop_stream(handle, stream_handle) };
|
||||||
log(&format!("Session {} aborted, skipping final flush", shared.session_id));
|
log(&format!("Session {} aborted, skipping final flush", shared.session_id));
|
||||||
|
if let Some(mut r) = recorder {
|
||||||
|
r.log_event("aborted (new session took over)");
|
||||||
|
r.save();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drain remaining audio
|
|
||||||
let remaining = {
|
|
||||||
let mut buf = audio_buf.lock().unwrap();
|
|
||||||
std::mem::take(&mut *buf)
|
|
||||||
};
|
|
||||||
if !remaining.is_empty() {
|
|
||||||
unsafe {
|
|
||||||
moonshine_transcribe_add_audio_to_stream(
|
|
||||||
handle, stream_handle,
|
|
||||||
remaining.as_ptr(), remaining.len() as u64,
|
|
||||||
SAMPLE_RATE, 0,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Final flush
|
// Final flush
|
||||||
unsafe { moonshine_stop_stream(handle, stream_handle) };
|
unsafe { moonshine_stop_stream(handle, stream_handle) };
|
||||||
let mut t_ptr: *mut transcript_t = std::ptr::null_mut();
|
let mut t_ptr: *mut transcript_t = std::ptr::null_mut();
|
||||||
@@ -234,6 +393,10 @@ fn transcriber_loop(
|
|||||||
let t = unsafe { &*t_ptr };
|
let t = unsafe { &*t_ptr };
|
||||||
let mut new_segments: Vec<String> = Vec::new();
|
let mut new_segments: Vec<String> = Vec::new();
|
||||||
|
|
||||||
|
if let Some(ref mut r) = recorder {
|
||||||
|
log_transcript_lines(r, t_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
for i in 0..t.line_count as usize {
|
for i in 0..t.line_count as usize {
|
||||||
let line = unsafe { &*t.lines.add(i) };
|
let line = unsafe { &*t.lines.add(i) };
|
||||||
if line.text.is_null() || line.is_complete == 0 {
|
if line.text.is_null() || line.is_complete == 0 {
|
||||||
@@ -255,10 +418,32 @@ fn transcriber_loop(
|
|||||||
for (i, text) in new_segments.iter().enumerate() {
|
for (i, text) in new_segments.iter().enumerate() {
|
||||||
let prefix = if i == last { "F" } else { "P" };
|
let prefix = if i == last { "F" } else { "P" };
|
||||||
shared.send_msg(prefix, text);
|
shared.send_msg(prefix, text);
|
||||||
|
if let Some(ref mut r) = recorder {
|
||||||
|
r.log_event(&format!("TX {} \"{}\"", prefix, text));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
shared.send_msg("F", "");
|
shared.send_msg("F", "");
|
||||||
|
if let Some(ref mut r) = recorder {
|
||||||
|
r.log_event("TX F (empty)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(mut r) = recorder {
|
||||||
|
r.log_event("session ended");
|
||||||
|
r.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn log_transcript_lines(recorder: &mut DebugRecorder, t_ptr: *const transcript_t) {
|
||||||
|
let t = unsafe { &*t_ptr };
|
||||||
|
for i in 0..t.line_count as usize {
|
||||||
|
let line = unsafe { &*t.lines.add(i) };
|
||||||
|
if line.text.is_null() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
recorder.log_segment(line, if line.is_complete != 0 { "complete" } else { "partial" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,8 +474,7 @@ fn send_new_segments(
|
|||||||
// ─── cpal ─────────────────────────────────────────────────────────────────
|
// ─── cpal ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
fn start_cpal(
|
fn start_cpal(
|
||||||
audio_buf: Arc<Mutex<Vec<f32>>>,
|
tx: mpsc::Sender<Vec<f32>>,
|
||||||
stop_signal: Arc<AtomicBool>,
|
|
||||||
) -> Result<cpal::Stream> {
|
) -> Result<cpal::Stream> {
|
||||||
let host = cpal::default_host();
|
let host = cpal::default_host();
|
||||||
let dev = host
|
let dev = host
|
||||||
@@ -314,6 +498,7 @@ fn start_cpal(
|
|||||||
config.channels = 1;
|
config.channels = 1;
|
||||||
}
|
}
|
||||||
config.sample_rate = SampleRate(16000);
|
config.sample_rate = SampleRate(16000);
|
||||||
|
config.buffer_size = cpal::BufferSize::Fixed(800);
|
||||||
|
|
||||||
let err_fn = |e: cpal::StreamError| log(&format!("cpal error: {}", e));
|
let err_fn = |e: cpal::StreamError| log(&format!("cpal error: {}", e));
|
||||||
|
|
||||||
@@ -321,9 +506,7 @@ fn start_cpal(
|
|||||||
SampleFormat::F32 => dev.build_input_stream(
|
SampleFormat::F32 => dev.build_input_stream(
|
||||||
&config,
|
&config,
|
||||||
move |data: &[f32], _: &_| {
|
move |data: &[f32], _: &_| {
|
||||||
if !stop_signal.load(Ordering::Relaxed) {
|
let _ = tx.send(data.to_vec());
|
||||||
audio_buf.lock().unwrap().extend_from_slice(data);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
err_fn,
|
err_fn,
|
||||||
None,
|
None,
|
||||||
@@ -331,9 +514,7 @@ fn start_cpal(
|
|||||||
SampleFormat::I16 => dev.build_input_stream(
|
SampleFormat::I16 => dev.build_input_stream(
|
||||||
&config,
|
&config,
|
||||||
move |data: &[i16], _: &_| {
|
move |data: &[i16], _: &_| {
|
||||||
if !stop_signal.load(Ordering::Relaxed) {
|
let _ = tx.send(data.iter().map(|&x| x as f32 / 32768.0).collect());
|
||||||
audio_buf.lock().unwrap().extend(data.iter().map(|&x| x as f32 / 32768.0));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
err_fn,
|
err_fn,
|
||||||
None,
|
None,
|
||||||
@@ -341,9 +522,7 @@ fn start_cpal(
|
|||||||
SampleFormat::U8 => dev.build_input_stream(
|
SampleFormat::U8 => dev.build_input_stream(
|
||||||
&config,
|
&config,
|
||||||
move |data: &[u8], _: &_| {
|
move |data: &[u8], _: &_| {
|
||||||
if !stop_signal.load(Ordering::Relaxed) {
|
let _ = tx.send(data.iter().map(|&x| (x as f32 - 128.0) / 128.0).collect());
|
||||||
audio_buf.lock().unwrap().extend(data.iter().map(|&x| (x as f32 - 128.0) / 128.0));
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
err_fn,
|
err_fn,
|
||||||
None,
|
None,
|
||||||
@@ -468,17 +647,22 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
let mut args = first.into_iter().chain(args);
|
let mut args = first.into_iter().chain(args);
|
||||||
let mut model_dir = default_model;
|
let mut model_dir = default_model;
|
||||||
|
let mut debug = false;
|
||||||
|
|
||||||
while let Some(a) = args.next() {
|
while let Some(a) = args.next() {
|
||||||
match a.as_str() {
|
match a.as_str() {
|
||||||
"--model-dir" | "-m" => {
|
"--model-dir" | "-m" => {
|
||||||
model_dir = args.next().unwrap_or(model_dir);
|
model_dir = args.next().unwrap_or(model_dir);
|
||||||
}
|
}
|
||||||
|
"--debug" => {
|
||||||
|
debug = true;
|
||||||
|
}
|
||||||
"--help" | "-h" => {
|
"--help" | "-h" => {
|
||||||
println!("Usage: rvsttd [--model-dir DIR]");
|
println!("Usage: rvsttd [--model-dir DIR] [--debug]");
|
||||||
println!(" rvsttd fetch [DIR]");
|
println!(" rvsttd fetch [DIR]");
|
||||||
println!("Listens on TCP {}", BIND_ADDR);
|
println!("Listens on TCP {}", BIND_ADDR);
|
||||||
println!("Model: medium-streaming (Moonshine)");
|
println!("Model: medium-streaming (Moonshine)");
|
||||||
|
println!("--debug: save session audio + transcript log to ~/.rvsttd/debug/");
|
||||||
println!("'rvsttd fetch' downloads the English medium-streaming model");
|
println!("'rvsttd fetch' downloads the English medium-streaming model");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
@@ -486,6 +670,15 @@ fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let debug_dir = if debug {
|
||||||
|
let d = PathBuf::from(&home).join(".rvsttd").join("debug");
|
||||||
|
std::fs::create_dir_all(&d).ok();
|
||||||
|
log(&format!("Debug mode enabled — sessions saved to {}", d.display()));
|
||||||
|
Some(d)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let model_path = std::fs::canonicalize(&model_dir)
|
let model_path = std::fs::canonicalize(&model_dir)
|
||||||
.unwrap_or_else(|_| std::path::PathBuf::from(&model_dir));
|
.unwrap_or_else(|_| std::path::PathBuf::from(&model_dir));
|
||||||
|
|
||||||
@@ -547,6 +740,7 @@ fn main() -> Result<()> {
|
|||||||
writer: Mutex::new(writer_stream.try_clone()?),
|
writer: Mutex::new(writer_stream.try_clone()?),
|
||||||
session_id: new_session_id,
|
session_id: new_session_id,
|
||||||
transcriber_handle,
|
transcriber_handle,
|
||||||
|
debug_dir: debug_dir.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
log(&format!("PTT on session {}", new_session_id));
|
log(&format!("PTT on session {}", new_session_id));
|
||||||
|
|||||||
Reference in New Issue
Block a user