-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f741b31
commit 54f05cc
Showing
6 changed files
with
187 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,61 @@ | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using System.Linq; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace OpenAI.Chat | ||
{ | ||
[JsonConverter(typeof(AudioOutputConverter))] | ||
public sealed class AudioOutput | ||
{ | ||
internal AudioOutput(string id, int expiresAtUnixSeconds, ReadOnlyMemory<byte> data, string transcript) | ||
internal AudioOutput(string id, int? expiresAtUnixSeconds, Memory<byte> data, string transcript) | ||
{ | ||
Id = id; | ||
ExpiresAtUnixSeconds = expiresAtUnixSeconds; | ||
Data = data; | ||
this.data = data; | ||
Transcript = transcript; | ||
ExpiresAtUnixSeconds = expiresAtUnixSeconds; | ||
} | ||
|
||
public string Id { get; } | ||
public string Id { get; private set; } | ||
|
||
public string Transcript { get; private set; } | ||
|
||
public int ExpiresAtUnixSeconds { get; } | ||
private Memory<byte> data; | ||
|
||
public DateTime ExpiresAt => DateTimeOffset.FromUnixTimeSeconds(ExpiresAtUnixSeconds).DateTime; | ||
public ReadOnlyMemory<byte> Data => data; | ||
|
||
public ReadOnlyMemory<byte> Data { get; } | ||
public int? ExpiresAtUnixSeconds { get; private set; } | ||
|
||
public string Transcript { get; } | ||
public DateTime? ExpiresAt => ExpiresAtUnixSeconds.HasValue | ||
? DateTimeOffset.FromUnixTimeSeconds(ExpiresAtUnixSeconds.Value).DateTime | ||
: null; | ||
|
||
public override string ToString() => Transcript ?? string.Empty; | ||
|
||
internal void AppendFrom(AudioOutput other) | ||
{ | ||
if (other == null) { return; } | ||
|
||
if (!string.IsNullOrWhiteSpace(other.Id)) | ||
{ | ||
Id = other.Id; | ||
} | ||
|
||
if (other.ExpiresAtUnixSeconds.HasValue) | ||
{ | ||
ExpiresAtUnixSeconds = other.ExpiresAtUnixSeconds; | ||
} | ||
|
||
if (!string.IsNullOrWhiteSpace(other.Transcript)) | ||
{ | ||
Transcript += other.Transcript; | ||
} | ||
|
||
if (other.Data.Length > 0) | ||
{ | ||
data = data.ToArray().Concat(other.Data.ToArray()).ToArray(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters