Skip to content

Commit

Permalink
Merge pull request #44 from Swimburger/main
Browse files Browse the repository at this point in the history
Make Microphone stream sample Windows compatible, add readmes
  • Loading branch information
Swimburger authored Aug 16, 2024
2 parents c85d661 + 66e98b6 commit 40127ec
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Samples/MicrophoneStream/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using AssemblyAI.Realtime;
using Microsoft.Extensions.Configuration;

var transcriptWords = new SortedDictionary<int, string>();

string BuildTranscript()
{
var stringBuilder = new StringBuilder();
Expand Down Expand Up @@ -33,7 +35,8 @@ string BuildTranscript()
});

transcriber.PartialTranscriptReceived.Subscribe(transcript =>
{ // don't do anything if nothing was said
{
// don't do anything if nothing was said
if (string.IsNullOrEmpty(transcript.Text)) return;
transcriptWords[transcript.AudioStart] = transcript.Text;
Expand Down Expand Up @@ -65,7 +68,8 @@ string BuildTranscript()
Console.WriteLine("Starting recording");

var soxArguments = string.Join(' ', [
"--default-device",
// --default-device doesn't work on Windows
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "-t waveaudio default" : "--default-device",
"--no-show-progress",
"--rate 16000",
"--channels 1",
Expand Down Expand Up @@ -99,4 +103,4 @@ string BuildTranscript()
}

soxProcess.Kill();
await transcriber.CloseAsync();
await transcriber.CloseAsync();
18 changes: 18 additions & 0 deletions Samples/MicrophoneStream/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Transcribe audio from the microphone in real-time

The following things are required to run the sample:
* [.NET 8 or up](https://dotnet.microsoft.com/en-us/download)
* [Install SoX and add it to the PATH environment variable](https://sourceforge.net/projects/sox/)
* An [AssemblyAI](https://www.assemblyai.com/dashboard/signup) account with credit card set up
* Configure [your AssemblyAI API key](https://www.assemblyai.com/app/account) using .NET user-secrets:
```bash
dotnet user-secrets set AssemblyAI:ApiKey [YOUR_API_KEY]
```

Now run the sample:

```bash
dotnet run
```

Speak into your microphone to see your speech transcribed in real-time.
8 changes: 8 additions & 0 deletions Samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Samples for the AssemblyAI C# .NET SDK

This solution contains a variety of samples that show how to use the AssemblyAI SDK for C# .NET.

* [MicrophoneStream](./MicrophoneStream): A console app to transcribe speech from the microphone in real-time.
* [Avalonia](./Avalonia): An Avalonia app that lets you transcribe audio files, prompt LLMs using LeMUR, and transcribe speech from the microphone in real-time.
* [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.
* [TwilioVoice](./TwilioVoice): An ASP.NET Core app that uses Twilio Media Streams to transcribe speech from Twilio Voice calls in real-time.

0 comments on commit 40127ec

Please sign in to comment.