-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add startup info and microphone device listing
- Loading branch information
1 parent
09961d9
commit e3446e6
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using NAudio.CoreAudioApi; | ||
using NAudio.Wave; | ||
|
||
namespace ButterSTT | ||
{ | ||
public static class AudioUtils | ||
{ | ||
public static IEnumerable<( | ||
int index, | ||
WaveInCapabilities device, | ||
MMDevice? mmDevice | ||
)> EnumerateWaveInDevices() | ||
{ | ||
using var enumerator = new MMDeviceEnumerator(); | ||
for (var i = -1; i < WaveInEvent.DeviceCount; i++) | ||
{ | ||
(int index, WaveInCapabilities device, MMDevice? mmDevice) device = ( | ||
i, | ||
WaveInEvent.GetCapabilities(i), | ||
null | ||
); | ||
|
||
if (i >= 0) | ||
{ | ||
var mmDevices = enumerator.EnumerateAudioEndPoints( | ||
DataFlow.Capture, | ||
DeviceState.Active | ||
); | ||
|
||
// Try the most likely index first, this makes it more likely to get the | ||
// correct name if multiple are named only slightly differently | ||
if (mmDevices.Count > i) | ||
{ | ||
try | ||
{ | ||
var likelyDevice = mmDevices[i]; | ||
if (likelyDevice.FriendlyName.StartsWith(device.device.ProductName)) | ||
device.mmDevice = likelyDevice; | ||
} | ||
catch { } | ||
} | ||
|
||
// If the device isn't in the same index, search all devices | ||
if (device.mmDevice == null) | ||
{ | ||
foreach (var mmDevice in mmDevices) | ||
{ | ||
try | ||
{ | ||
if (mmDevice.FriendlyName.StartsWith(device.device.ProductName)) | ||
{ | ||
device.mmDevice = mmDevice; | ||
break; | ||
} | ||
} | ||
catch { } | ||
} | ||
} | ||
} | ||
|
||
yield return device; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace ButterSTT | ||
{ | ||
public static class Constants | ||
{ | ||
public static readonly string Name = "ButterSTT"; | ||
public static readonly string Version = "0.2.3"; | ||
public static readonly string Url = "https://github.com/ButterscotchV/ButterSTT"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters