Skip to content

Commit aa0baf8

Browse files
authored
Enable semantic voice activity detection option (#545)
Enable semantic voice activity detection option
1 parent ec46fd3 commit aa0baf8

12 files changed

+110
-57
lines changed

api/OpenAI.net8.0.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3828,6 +3828,23 @@ public class ResponseStartedUpdate : RealtimeUpdate, IJsonModel<ResponseStartedU
38283828
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
38293829
}
38303830
[Experimental("OPENAI002")]
3831+
public readonly partial struct SemanticEagernessLevel : IEquatable<SemanticEagernessLevel> {
3832+
public SemanticEagernessLevel(string value);
3833+
public static SemanticEagernessLevel Auto { get; }
3834+
public static SemanticEagernessLevel High { get; }
3835+
public static SemanticEagernessLevel Low { get; }
3836+
public static SemanticEagernessLevel Medium { get; }
3837+
public readonly bool Equals(SemanticEagernessLevel other);
3838+
[EditorBrowsable(EditorBrowsableState.Never)]
3839+
public override readonly bool Equals(object obj);
3840+
[EditorBrowsable(EditorBrowsableState.Never)]
3841+
public override readonly int GetHashCode();
3842+
public static bool operator ==(SemanticEagernessLevel left, SemanticEagernessLevel right);
3843+
public static implicit operator SemanticEagernessLevel(string value);
3844+
public static bool operator !=(SemanticEagernessLevel left, SemanticEagernessLevel right);
3845+
public override readonly string ToString();
3846+
}
3847+
[Experimental("OPENAI002")]
38313848
public class TranscriptionSessionConfiguredUpdate : RealtimeUpdate, IJsonModel<TranscriptionSessionConfiguredUpdate>, IPersistableModel<TranscriptionSessionConfiguredUpdate> {
38323849
public RealtimeContentModalities ContentModalities { get; }
38333850
public RealtimeAudioFormat InputAudioFormat { get; }
@@ -3862,6 +3879,7 @@ public enum TurnDetectionKind {
38623879
public class TurnDetectionOptions : IJsonModel<TurnDetectionOptions>, IPersistableModel<TurnDetectionOptions> {
38633880
public TurnDetectionKind Kind { get; }
38643881
public static TurnDetectionOptions CreateDisabledTurnDetectionOptions();
3882+
public static TurnDetectionOptions CreateSemanticVoiceActivityTurnDetectionOptions(SemanticEagernessLevel? eagernessLevel = null, bool? enableAutomaticResponseCreation = null, bool? enableResponseInterruption = null);
38653883
public static TurnDetectionOptions CreateServerVoiceActivityTurnDetectionOptions(float? detectionThreshold = null, TimeSpan? prefixPaddingDuration = null, TimeSpan? silenceDuration = null, bool? enableAutomaticResponseCreation = null, bool? enableResponseInterruption = null);
38663884
protected virtual TurnDetectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
38673885
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);

api/OpenAI.netstandard2.0.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,6 +3370,22 @@ public class ResponseStartedUpdate : RealtimeUpdate, IJsonModel<ResponseStartedU
33703370
protected override RealtimeUpdate PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
33713371
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
33723372
}
3373+
public readonly partial struct SemanticEagernessLevel : IEquatable<SemanticEagernessLevel> {
3374+
public SemanticEagernessLevel(string value);
3375+
public static SemanticEagernessLevel Auto { get; }
3376+
public static SemanticEagernessLevel High { get; }
3377+
public static SemanticEagernessLevel Low { get; }
3378+
public static SemanticEagernessLevel Medium { get; }
3379+
public readonly bool Equals(SemanticEagernessLevel other);
3380+
[EditorBrowsable(EditorBrowsableState.Never)]
3381+
public override readonly bool Equals(object obj);
3382+
[EditorBrowsable(EditorBrowsableState.Never)]
3383+
public override readonly int GetHashCode();
3384+
public static bool operator ==(SemanticEagernessLevel left, SemanticEagernessLevel right);
3385+
public static implicit operator SemanticEagernessLevel(string value);
3386+
public static bool operator !=(SemanticEagernessLevel left, SemanticEagernessLevel right);
3387+
public override readonly string ToString();
3388+
}
33733389
public class TranscriptionSessionConfiguredUpdate : RealtimeUpdate, IJsonModel<TranscriptionSessionConfiguredUpdate>, IPersistableModel<TranscriptionSessionConfiguredUpdate> {
33743390
public RealtimeContentModalities ContentModalities { get; }
33753391
public RealtimeAudioFormat InputAudioFormat { get; }
@@ -3401,6 +3417,7 @@ public enum TurnDetectionKind {
34013417
public class TurnDetectionOptions : IJsonModel<TurnDetectionOptions>, IPersistableModel<TurnDetectionOptions> {
34023418
public TurnDetectionKind Kind { get; }
34033419
public static TurnDetectionOptions CreateDisabledTurnDetectionOptions();
3420+
public static TurnDetectionOptions CreateSemanticVoiceActivityTurnDetectionOptions(SemanticEagernessLevel? eagernessLevel = null, bool? enableAutomaticResponseCreation = null, bool? enableResponseInterruption = null);
34043421
public static TurnDetectionOptions CreateServerVoiceActivityTurnDetectionOptions(float? detectionThreshold = null, TimeSpan? prefixPaddingDuration = null, TimeSpan? silenceDuration = null, bool? enableAutomaticResponseCreation = null, bool? enableResponseInterruption = null);
34053422
protected virtual TurnDetectionOptions JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
34063423
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);

scripts/Export-Api.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ function Invoke-GenAPI {
258258
# Remove Diagnostics.DebuggerStepThrough attribute.
259259
$content = $content -creplace ".*Diagnostics.DebuggerStepThrough.*\n", ""
260260

261+
# Remove ModelReaderWriterBuildable attributes.
262+
$content = $content -creplace '\[ModelReaderWriterBuildable\(typeof\([^\)]+\)\)\]\s*', ''
263+
261264
# Remove internal APIs.
262265
$content = $content -creplace " * internal.*`n", ""
263266

src/Custom/Realtime/GeneratorStubs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ namespace OpenAI.Realtime;
1111
[CodeGenType("RealtimeResponseUsage")] public partial class ConversationTokenUsage { }
1212
[CodeGenType("RealtimeToolType")] public readonly partial struct ConversationToolKind { }
1313
[CodeGenType("DotNetRealtimeVoiceIds")] public readonly partial struct ConversationVoice { }
14+
[CodeGenType("RealtimeSemanticVadTurnDetectionEagerness")] public readonly partial struct SemanticEagernessLevel { }

src/Custom/Realtime/Internal/GeneratorStubs.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ namespace OpenAI.Realtime;
3535
[Experimental("OPENAI002")][CodeGenType("RealtimeResponseStatusDetailsType")] internal readonly partial struct InternalRealtimeResponseStatusDetailsType { }
3636
[Experimental("OPENAI002")][CodeGenType("RealtimeResponseVoice")] internal readonly partial struct InternalRealtimeResponseVoice { }
3737
[Experimental("OPENAI002")][CodeGenType("RealtimeSemanticVadTurnDetection")] internal partial class InternalRealtimeSemanticVadTurnDetection { }
38-
[Experimental("OPENAI002")][CodeGenType("RealtimeSemanticVadTurnDetectionEagerness")] internal readonly partial struct InternalRealtimeSemanticVadTurnDetectionEagerness { }
3938
[Experimental("OPENAI002")][CodeGenType("RealtimeServerEventConversationCreated")] internal partial class InternalRealtimeServerEventConversationCreated { }
4039
[Experimental("OPENAI002")][CodeGenType("RealtimeServerEventConversationCreatedConversation")] internal partial class InternalRealtimeServerEventConversationCreatedConversation { }
4140
[Experimental("OPENAI002")][CodeGenType("RealtimeServerEventConversationItemInputAudioTranscriptionFailedError")] internal partial class InternalRealtimeServerEventConversationItemInputAudioTranscriptionFailedError { }

src/Custom/Realtime/TurnDetectionOptions.Serialization.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal static TurnDetectionOptions DeserializeTurnDetectionOptions(JsonElement
2020
{
2121
case "none": return InternalRealtimeNoTurnDetection.DeserializeInternalRealtimeNoTurnDetection(element, options);
2222
case "server_vad": return InternalRealtimeServerVadTurnDetection.DeserializeInternalRealtimeServerVadTurnDetection(element, options);
23+
case "semantic_vad": return InternalRealtimeSemanticVadTurnDetection.DeserializeInternalRealtimeSemanticVadTurnDetection(element, options);
2324
default: return null;
2425
}
2526
}

src/Custom/Realtime/TurnDetectionOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public static TurnDetectionOptions CreateServerVoiceActivityTurnDetectionOptions
3535
};
3636
}
3737

38-
internal static TurnDetectionOptions CreateSemanticVoiceActivityTurnDetectionOptions(
39-
InternalRealtimeSemanticVadTurnDetectionEagerness? eagernessLevel = null,
38+
public static TurnDetectionOptions CreateSemanticVoiceActivityTurnDetectionOptions(
39+
SemanticEagernessLevel? eagernessLevel = null,
4040
bool? enableAutomaticResponseCreation = null,
4141
bool? enableResponseInterruption = null)
4242
{

src/Generated/Models/Realtime/InternalRealtimeSemanticVadTurnDetection.Serialization.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal static InternalRealtimeSemanticVadTurnDetection DeserializeInternalReal
5757
bool? responseCreationEnabled = default;
5858
bool? responseInterruptionEnabled = default;
5959
IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>();
60-
InternalRealtimeSemanticVadTurnDetectionEagerness? eagerness = default;
60+
SemanticEagernessLevel? eagerness = default;
6161
foreach (var prop in element.EnumerateObject())
6262
{
6363
if (prop.NameEquals("type"u8))
@@ -89,7 +89,7 @@ internal static InternalRealtimeSemanticVadTurnDetection DeserializeInternalReal
8989
{
9090
continue;
9191
}
92-
eagerness = new InternalRealtimeSemanticVadTurnDetectionEagerness(prop.Value.GetString());
92+
eagerness = new SemanticEagernessLevel(prop.Value.GetString());
9393
continue;
9494
}
9595
// Plugin customization: remove options.Format != "W" check

src/Generated/Models/Realtime/InternalRealtimeSemanticVadTurnDetection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public InternalRealtimeSemanticVadTurnDetection() : this(TurnDetectionKind.Seman
1313
{
1414
}
1515

16-
internal InternalRealtimeSemanticVadTurnDetection(TurnDetectionKind kind, bool? responseCreationEnabled, bool? responseInterruptionEnabled, IDictionary<string, BinaryData> additionalBinaryDataProperties, InternalRealtimeSemanticVadTurnDetectionEagerness? eagerness) : base(kind, responseCreationEnabled, responseInterruptionEnabled, additionalBinaryDataProperties)
16+
internal InternalRealtimeSemanticVadTurnDetection(TurnDetectionKind kind, bool? responseCreationEnabled, bool? responseInterruptionEnabled, IDictionary<string, BinaryData> additionalBinaryDataProperties, SemanticEagernessLevel? eagerness) : base(kind, responseCreationEnabled, responseInterruptionEnabled, additionalBinaryDataProperties)
1717
{
1818
Eagerness = eagerness;
1919
}
2020

21-
internal InternalRealtimeSemanticVadTurnDetectionEagerness? Eagerness { get; set; }
21+
public SemanticEagernessLevel? Eagerness { get; set; }
2222
}
2323
}

src/Generated/Models/Realtime/InternalRealtimeSemanticVadTurnDetectionEagerness.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)