openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
src/Custom/Audio/AudioTranscription.Serialization.cs
29lines · modecode
| 1 | using System; |
| 2 | using System.ClientModel.Primitives; |
| 3 | using System.Collections.Generic; |
| 4 | using System.Text.Json; |
| 5 | |
| 6 | namespace OpenAI.Audio; |
| 7 | |
| 8 | public partial class AudioTranscription |
| 9 | { |
| 10 | internal static AudioTranscription FromResponse(PipelineResponse response) |
| 11 | { |
| 12 | // Customization: handle plain text responses (SRT/VTT formats) |
| 13 | if (response?.Headers?.TryGetValue("Content-Type", out string contentType) == true && |
| 14 | contentType.StartsWith("text/plain", StringComparison.Ordinal)) |
| 15 | { |
| 16 | return new AudioTranscription( |
| 17 | task: default, |
| 18 | language: null, |
| 19 | duration: null, |
| 20 | text: response.Content?.ToString(), |
| 21 | words: new ChangeTrackingList<TranscribedWord>(), |
| 22 | segments: new ChangeTrackingList<TranscribedSegment>(), |
| 23 | additionalBinaryDataProperties: new Dictionary<string, BinaryData>()); |
| 24 | } |
| 25 | |
| 26 | using var document = JsonDocument.Parse(response.Content); |
| 27 | return DeserializeAudioTranscription(document.RootElement, null); |
| 28 | } |
| 29 | } |
| 30 | |