openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
examples/Audio/Example03_VerboseTranscription.cs
42lines · modecode
| 1 | using NUnit.Framework; |
| 2 | using OpenAI.Audio; |
| 3 | using System; |
| 4 | using System.IO; |
| 5 | |
| 6 | namespace OpenAI.Examples; |
| 7 | |
| 8 | public partial class AudioExamples |
| 9 | { |
| 10 | [Test] |
| 11 | public void Example03_VerboseTranscription() |
| 12 | { |
| 13 | AudioClient client = new("whisper-1", Environment.GetEnvironmentVariable("OPENAI_API_KEY")); |
| 14 | |
| 15 | string audioFilePath = Path.Combine("Assets", "audio_houseplant_care.mp3"); |
| 16 | |
| 17 | AudioTranscriptionOptions options = new() |
| 18 | { |
| 19 | ResponseFormat = AudioTranscriptionFormat.Verbose, |
| 20 | Granularities = AudioTimestampGranularities.Word | AudioTimestampGranularities.Segment, |
| 21 | }; |
| 22 | |
| 23 | AudioTranscription transcription = client.TranscribeAudio(audioFilePath, options); |
| 24 | |
| 25 | Console.WriteLine("Transcription:"); |
| 26 | Console.WriteLine($"{transcription.Text}"); |
| 27 | |
| 28 | Console.WriteLine(); |
| 29 | Console.WriteLine($"Words:"); |
| 30 | foreach (TranscribedWord word in transcription.Words) |
| 31 | { |
| 32 | Console.WriteLine($" {word.Word,15} : {word.Start.TotalMilliseconds,5:0} - {word.End.TotalMilliseconds,5:0}"); |
| 33 | } |
| 34 | |
| 35 | Console.WriteLine(); |
| 36 | Console.WriteLine($"Segments:"); |
| 37 | foreach (TranscribedSegment segment in transcription.Segments) |
| 38 | { |
| 39 | Console.WriteLine($" {segment.Text,90} : {segment.Start.TotalMilliseconds,5:0} - {segment.End.TotalMilliseconds,5:0}"); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |