Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 40127ec

Browse files
authored
Merge pull request #44 from Swimburger/main
Make Microphone stream sample Windows compatible, add readmes
2 parents c85d661 + 66e98b6 commit 40127ec

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

Samples/MicrophoneStream/Program.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.Diagnostics;
2+
using System.Runtime.InteropServices;
23
using System.Text;
34
using AssemblyAI.Realtime;
45
using Microsoft.Extensions.Configuration;
56

67
var transcriptWords = new SortedDictionary<int, string>();
8+
79
string BuildTranscript()
810
{
911
var stringBuilder = new StringBuilder();
@@ -33,7 +35,8 @@ string BuildTranscript()
3335
});
3436

3537
transcriber.PartialTranscriptReceived.Subscribe(transcript =>
36-
{ // don't do anything if nothing was said
38+
{
39+
// don't do anything if nothing was said
3740
if (string.IsNullOrEmpty(transcript.Text)) return;
3841
transcriptWords[transcript.AudioStart] = transcript.Text;
3942

@@ -65,7 +68,8 @@ string BuildTranscript()
6568
Console.WriteLine("Starting recording");
6669

6770
var soxArguments = string.Join(' ', [
68-
"--default-device",
71+
// --default-device doesn't work on Windows
72+
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "-t waveaudio default" : "--default-device",
6973
"--no-show-progress",
7074
"--rate 16000",
7175
"--channels 1",
@@ -99,4 +103,4 @@ string BuildTranscript()
99103
}
100104

101105
soxProcess.Kill();
102-
await transcriber.CloseAsync();
106+
await transcriber.CloseAsync();

Samples/MicrophoneStream/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Transcribe audio from the microphone in real-time
2+
3+
The following things are required to run the sample:
4+
* [.NET 8 or up](https://dotnet.microsoft.com/en-us/download)
5+
* [Install SoX and add it to the PATH environment variable](https://sourceforge.net/projects/sox/)
6+
* An [AssemblyAI](https://www.assemblyai.com/dashboard/signup) account with credit card set up
7+
* Configure [your AssemblyAI API key](https://www.assemblyai.com/app/account) using .NET user-secrets:
8+
```bash
9+
dotnet user-secrets set AssemblyAI:ApiKey [YOUR_API_KEY]
10+
```
11+
12+
Now run the sample:
13+
14+
```bash
15+
dotnet run
16+
```
17+
18+
Speak into your microphone to see your speech transcribed in real-time.

Samples/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Samples for the AssemblyAI C# .NET SDK
2+
3+
This solution contains a variety of samples that show how to use the AssemblyAI SDK for C# .NET.
4+
5+
* [MicrophoneStream](./MicrophoneStream): A console app to transcribe speech from the microphone in real-time.
6+
* [Avalonia](./Avalonia): An Avalonia app that lets you transcribe audio files, prompt LLMs using LeMUR, and transcribe speech from the microphone in real-time.
7+
* [BlazorSample](./BlazorSample): A Blazor WASM and Server app that lets you transcribe audio files, prompt LLMs using LeMUR, and transcribe speech from the microphone in real-time.
8+
* [TwilioVoice](./TwilioVoice): An ASP.NET Core app that uses Twilio Media Streams to transcribe speech from Twilio Voice calls in real-time.

0 commit comments

Comments
 (0)