Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 20 additions & 0 deletions src/Custom/Audio/AudioClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ public virtual AsyncCollectionResult<StreamingAudioTranscriptionUpdate> Transcri
Argument.AssertNotNull(audio, nameof(audio));
Argument.AssertNotNullOrEmpty(audioFilename, nameof(audioFilename));

if (string.Equals(_model, "whisper-1", StringComparison.OrdinalIgnoreCase))
{
throw new NotSupportedException($"The selected model {_model} does not support streaming transcription. Please use a compatible model.");
}

MultiPartFormDataBinaryContent content
= CreatePerCallTranscriptionOptions(options, stream: true)
.ToMultipartContent(audio, audioFilename);
Expand All @@ -245,6 +250,11 @@ public virtual AsyncCollectionResult<StreamingAudioTranscriptionUpdate> Transcri
{
Argument.AssertNotNullOrEmpty(audioFilePath, nameof(audioFilePath));

if (string.Equals(_model, "whisper-1", StringComparison.OrdinalIgnoreCase))
{
throw new NotSupportedException($"The selected model {_model} does not support streaming transcription. Please use a compatible model.");
}

FileStream inputStream = File.OpenRead(audioFilePath);

MultiPartFormDataBinaryContent content
Expand All @@ -266,6 +276,11 @@ public virtual CollectionResult<StreamingAudioTranscriptionUpdate> TranscribeAud
Argument.AssertNotNull(audio, nameof(audio));
Argument.AssertNotNullOrEmpty(audioFilename, nameof(audioFilename));

if (string.Equals(_model, "whisper-1", StringComparison.OrdinalIgnoreCase))
{
throw new NotSupportedException($"The selected model {_model} does not support streaming transcription. Please use a compatible model.");
}

MultiPartFormDataBinaryContent content
= CreatePerCallTranscriptionOptions(options, stream: true)
.ToMultipartContent(audio, audioFilename);
Expand All @@ -282,6 +297,11 @@ public virtual CollectionResult<StreamingAudioTranscriptionUpdate> TranscribeAud
{
Argument.AssertNotNullOrEmpty(audioFilePath, nameof(audioFilePath));

if (string.Equals(_model, "whisper-1", StringComparison.OrdinalIgnoreCase))
{
throw new NotSupportedException($"The selected model {_model} does not support streaming transcription. Please use a compatible model.");
}

FileStream inputStream = File.OpenRead(audioFilePath);

MultiPartFormDataBinaryContent content
Expand Down
26 changes: 26 additions & 0 deletions tests/Audio/TranscriptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,30 @@ public async Task StreamingTranscriptionWorks(AudioSourceKind audioSourceKind)

inputStream?.Dispose();
}

[Test]
[TestCase(AudioSourceKind.UsingStream)]
[TestCase(AudioSourceKind.UsingFilePath)]
public void StreamingTranscriptionThrowsForWhisperModel(AudioSourceKind audioSourceKind)
{
AudioClient client = GetTestClient<AudioClient>(TestScenario.Audio_Whisper);
string filename = "audio_hello_world.mp3";
string path = Path.Combine("Assets", filename);

if (audioSourceKind == AudioSourceKind.UsingStream)
{
using FileStream inputStream = File.OpenRead(path);
Assert.Throws<NotSupportedException>(() =>
{
_ = client.TranscribeAudioStreamingAsync(inputStream, filename);
});
}
else if (audioSourceKind == AudioSourceKind.UsingFilePath)
{
Assert.Throws<NotSupportedException>(() =>
{
_ = client.TranscribeAudioStreamingAsync(path);
});
}
}
}