Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#nullable enable

namespace Soniox.Realtime.JsonConverters
{
/// <inheritdoc />
public sealed class TranslationConfigTypeJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::Soniox.Realtime.TranslationConfigType>
{
/// <inheritdoc />
public override global::Soniox.Realtime.TranslationConfigType Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::Soniox.Realtime.TranslationConfigTypeExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::Soniox.Realtime.TranslationConfigType)numValue;
}
case global::System.Text.Json.JsonTokenType.Null:
{
return default(global::Soniox.Realtime.TranslationConfigType);
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::Soniox.Realtime.TranslationConfigType value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::Soniox.Realtime.TranslationConfigTypeExtensions.ToValueString(value));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#nullable enable

namespace Soniox.Realtime.JsonConverters
{
/// <inheritdoc />
public sealed class TranslationConfigTypeNullableJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::Soniox.Realtime.TranslationConfigType?>
{
/// <inheritdoc />
public override global::Soniox.Realtime.TranslationConfigType? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::Soniox.Realtime.TranslationConfigTypeExtensions.ToEnum(stringValue);
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::Soniox.Realtime.TranslationConfigType)numValue;
}
case global::System.Text.Json.JsonTokenType.Null:
{
return default(global::Soniox.Realtime.TranslationConfigType?);
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::Soniox.Realtime.TranslationConfigType? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::Soniox.Realtime.TranslationConfigTypeExtensions.ToValueString(value.Value));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ namespace Soniox.Realtime
DefaultIgnoreCondition = global::System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull,
Converters = new global::System.Type[]
{
typeof(global::Soniox.Realtime.JsonConverters.TranslationConfigTypeJsonConverter),

typeof(global::Soniox.Realtime.JsonConverters.TranslationConfigTypeNullableJsonConverter),

typeof(global::Soniox.Realtime.JsonConverters.ServerEventJsonConverter),

typeof(global::Soniox.Realtime.JsonConverters.OneOfJsonConverter<string, object>),
Expand All @@ -27,6 +31,7 @@ namespace Soniox.Realtime
[global::System.Text.Json.Serialization.JsonSerializable(typeof(object))]
[global::System.Text.Json.Serialization.JsonSerializable(typeof(double))]
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::Soniox.Realtime.TranslationConfig))]
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::Soniox.Realtime.TranslationConfigType), TypeInfoPropertyName = "TranslationConfigType2")]
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::Soniox.Realtime.RealtimeToken))]
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::Soniox.Realtime.RealtimeResult))]
[global::System.Text.Json.Serialization.JsonSerializable(typeof(global::System.Collections.Generic.IList<global::Soniox.Realtime.RealtimeToken>))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,27 @@ public sealed partial class JsonSerializerContextTypes
/// <summary>
///
/// </summary>
public global::Soniox.Realtime.RealtimeToken? Type9 { get; set; }
public global::Soniox.Realtime.TranslationConfigType? Type9 { get; set; }
/// <summary>
///
/// </summary>
public global::Soniox.Realtime.RealtimeResult? Type10 { get; set; }
public global::Soniox.Realtime.RealtimeToken? Type10 { get; set; }
/// <summary>
///
/// </summary>
public global::System.Collections.Generic.IList<global::Soniox.Realtime.RealtimeToken>? Type11 { get; set; }
public global::Soniox.Realtime.RealtimeResult? Type11 { get; set; }
/// <summary>
///
/// </summary>
public global::Soniox.Realtime.RealtimeError? Type12 { get; set; }
public global::System.Collections.Generic.IList<global::Soniox.Realtime.RealtimeToken>? Type12 { get; set; }
/// <summary>
///
/// </summary>
public global::Soniox.Realtime.ServerEvent? Type13 { get; set; }
public global::Soniox.Realtime.RealtimeError? Type13 { get; set; }
/// <summary>
///
/// </summary>
public global::Soniox.Realtime.ServerEvent? Type14 { get; set; }

/// <summary>
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ public sealed partial class RealtimeConfig
/// Soniox API key. Permanent and temporary API keys are supported.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("api_key")]
public string? ApiKey { get; set; }
[global::System.Text.Json.Serialization.JsonRequired]
public required string ApiKey { get; set; }

/// <summary>
/// Realtime STT model id, for example stt-rt-v5.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("model")]
public string? Model { get; set; }
[global::System.Text.Json.Serialization.JsonRequired]
public required string Model { get; set; }

/// <summary>
/// Audio format; use auto for containerized streams or raw_* values with sample_rate.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("audio_format")]
public string? AudioFormat { get; set; }
[global::System.Text.Json.Serialization.JsonRequired]
public required string AudioFormat { get; set; }

/// <summary>
/// Sample rate in Hz for raw audio.
Expand Down Expand Up @@ -164,9 +167,9 @@ public sealed partial class RealtimeConfig
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
#endif
public RealtimeConfig(
string? apiKey,
string? model,
string? audioFormat,
string apiKey,
string model,
string audioFormat,
int? sampleRate,
int? numChannels,
global::System.Collections.Generic.IList<string>? languageHints,
Expand All @@ -181,9 +184,9 @@ public RealtimeConfig(
global::Soniox.Realtime.TranslationConfig? translation,
string? clientReferenceId)
{
this.ApiKey = apiKey;
this.Model = model;
this.AudioFormat = audioFormat;
this.ApiKey = apiKey ?? throw new global::System.ArgumentNullException(nameof(apiKey));
this.Model = model ?? throw new global::System.ArgumentNullException(nameof(model));
this.AudioFormat = audioFormat ?? throw new global::System.ArgumentNullException(nameof(audioFormat));
this.SampleRate = sampleRate;
this.NumChannels = numChannels;
this.LanguageHints = languageHints;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public sealed partial class RealtimeError
///
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("error_code")]
public int? ErrorCode { get; set; }
[global::System.Text.Json.Serialization.JsonRequired]
public required int ErrorCode { get; set; }

/// <summary>
///
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("error_message")]
public string? ErrorMessage { get; set; }
[global::System.Text.Json.Serialization.JsonRequired]
public required string ErrorMessage { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand All @@ -35,11 +37,11 @@ public sealed partial class RealtimeError
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
#endif
public RealtimeError(
int? errorCode,
string? errorMessage)
int errorCode,
string errorMessage)
{
this.ErrorCode = errorCode;
this.ErrorMessage = errorMessage;
this.ErrorMessage = errorMessage ?? throw new global::System.ArgumentNullException(nameof(errorMessage));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public sealed partial class TranslationConfig
///
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("type")]
public string? Type { get; set; }
[global::System.Text.Json.Serialization.JsonConverter(typeof(global::Soniox.Realtime.JsonConverters.TranslationConfigTypeJsonConverter))]
[global::System.Text.Json.Serialization.JsonRequired]
public required global::Soniox.Realtime.TranslationConfigType Type { get; set; }

/// <summary>
///
Expand Down Expand Up @@ -49,7 +51,7 @@ public sealed partial class TranslationConfig
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
#endif
public TranslationConfig(
string? type,
global::Soniox.Realtime.TranslationConfigType type,
string? targetLanguage,
string? languageA,
string? languageB)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

#nullable enable

namespace Soniox.Realtime
{
/// <summary>
///
/// </summary>
public enum TranslationConfigType
{
/// <summary>
///
/// </summary>
OneWay,
/// <summary>
///
/// </summary>
TwoWay,
}

/// <summary>
/// Enum extensions to do fast conversions without the reflection.
/// </summary>
public static class TranslationConfigTypeExtensions
{
/// <summary>
/// Converts an enum to a string.
/// </summary>
public static string ToValueString(this TranslationConfigType value)
{
return value switch
{
TranslationConfigType.OneWay => "one_way",
TranslationConfigType.TwoWay => "two_way",
_ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
};
}
/// <summary>
/// Converts an string to a enum.
/// </summary>
public static TranslationConfigType? ToEnum(string value)
{
return value switch
{
"one_way" => TranslationConfigType.OneWay,
"two_way" => TranslationConfigType.TwoWay,
_ => null,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public sealed partial class TtsAudio
/// Stream identifier this audio belongs to.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("stream_id")]
public string? StreamId { get; set; }
[global::System.Text.Json.Serialization.JsonRequired]
public required string StreamId { get; set; }

/// <summary>
/// Base64-encoded audio bytes.
Expand Down Expand Up @@ -55,12 +56,12 @@ public sealed partial class TtsAudio
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
#endif
public TtsAudio(
string? streamId,
string streamId,
string? audio,
bool? audioEnd,
global::Soniox.Realtime.Tts.TtsTimestamps? timestamps)
{
this.StreamId = streamId;
this.StreamId = streamId ?? throw new global::System.ArgumentNullException(nameof(streamId));
this.Audio = audio;
this.AudioEnd = audioEnd;
this.Timestamps = timestamps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ public sealed partial class TtsCancel
/// Stream identifier to cancel.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("stream_id")]
public string? StreamId { get; set; }
[global::System.Text.Json.Serialization.JsonRequired]
public required string StreamId { get; set; }

/// <summary>
/// True to cancel the active stream.
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("cancel")]
public bool? Cancel { get; set; }
[global::System.Text.Json.Serialization.JsonRequired]
public required bool Cancel { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
Expand All @@ -39,10 +41,10 @@ public sealed partial class TtsCancel
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
#endif
public TtsCancel(
string? streamId,
bool? cancel)
string streamId,
bool cancel)
{
this.StreamId = streamId;
this.StreamId = streamId ?? throw new global::System.ArgumentNullException(nameof(streamId));
this.Cancel = cancel;
}

Expand Down
Loading