diff --git a/Samples/MicrophoneStream/Program.cs b/Samples/MicrophoneStream/Program.cs index 33bc49a..b61aa74 100644 --- a/Samples/MicrophoneStream/Program.cs +++ b/Samples/MicrophoneStream/Program.cs @@ -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(); + string BuildTranscript() { var stringBuilder = new StringBuilder(); @@ -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; @@ -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", @@ -99,4 +103,4 @@ string BuildTranscript() } soxProcess.Kill(); -await transcriber.CloseAsync(); +await transcriber.CloseAsync(); \ No newline at end of file diff --git a/Samples/MicrophoneStream/README.md b/Samples/MicrophoneStream/README.md new file mode 100644 index 0000000..e1b0bda --- /dev/null +++ b/Samples/MicrophoneStream/README.md @@ -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. \ No newline at end of file diff --git a/Samples/README.md b/Samples/README.md new file mode 100644 index 0000000..1a1a8b2 --- /dev/null +++ b/Samples/README.md @@ -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. \ No newline at end of file