Skip to content

Commit 0af0524

Browse files
committed
Throw exception when streaming is used with unsupported whisper-1 model
1 parent 1dc8429 commit 0af0524

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Custom/Audio/AudioClient.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ public virtual AsyncCollectionResult<StreamingAudioTranscriptionUpdate> Transcri
229229
Argument.AssertNotNull(audio, nameof(audio));
230230
Argument.AssertNotNullOrEmpty(audioFilename, nameof(audioFilename));
231231

232+
if (string.Equals(_model, "whisper-1", StringComparison.OrdinalIgnoreCase))
233+
{
234+
throw new NotSupportedException($"The selected model {_model} does not support streaming transcription. Please use a compatible model.");
235+
}
236+
232237
MultiPartFormDataBinaryContent content
233238
= CreatePerCallTranscriptionOptions(options, stream: true)
234239
.ToMultipartContent(audio, audioFilename);
@@ -245,6 +250,11 @@ public virtual AsyncCollectionResult<StreamingAudioTranscriptionUpdate> Transcri
245250
{
246251
Argument.AssertNotNullOrEmpty(audioFilePath, nameof(audioFilePath));
247252

253+
if (string.Equals(_model, "whisper-1", StringComparison.OrdinalIgnoreCase))
254+
{
255+
throw new NotSupportedException($"The selected model {_model} does not support streaming transcription. Please use a compatible model.");
256+
}
257+
248258
FileStream inputStream = File.OpenRead(audioFilePath);
249259

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

279+
if (string.Equals(_model, "whisper-1", StringComparison.OrdinalIgnoreCase))
280+
{
281+
throw new NotSupportedException($"The selected model {_model} does not support streaming transcription. Please use a compatible model.");
282+
}
283+
269284
MultiPartFormDataBinaryContent content
270285
= CreatePerCallTranscriptionOptions(options, stream: true)
271286
.ToMultipartContent(audio, audioFilename);
@@ -282,6 +297,11 @@ public virtual CollectionResult<StreamingAudioTranscriptionUpdate> TranscribeAud
282297
{
283298
Argument.AssertNotNullOrEmpty(audioFilePath, nameof(audioFilePath));
284299

300+
if (string.Equals(_model, "whisper-1", StringComparison.OrdinalIgnoreCase))
301+
{
302+
throw new NotSupportedException($"The selected model {_model} does not support streaming transcription. Please use a compatible model.");
303+
}
304+
285305
FileStream inputStream = File.OpenRead(audioFilePath);
286306

287307
MultiPartFormDataBinaryContent content

tests/Audio/TranscriptionTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,30 @@ public async Task StreamingTranscriptionWorks(AudioSourceKind audioSourceKind)
322322

323323
inputStream?.Dispose();
324324
}
325+
326+
[Test]
327+
[TestCase(AudioSourceKind.UsingStream)]
328+
[TestCase(AudioSourceKind.UsingFilePath)]
329+
public void StreamingTranscriptionThrowsForWhisperModel(AudioSourceKind audioSourceKind)
330+
{
331+
AudioClient client = GetTestClient<AudioClient>(TestScenario.Audio_Whisper);
332+
string filename = "audio_hello_world.mp3";
333+
string path = Path.Combine("Assets", filename);
334+
335+
if (audioSourceKind == AudioSourceKind.UsingStream)
336+
{
337+
using FileStream inputStream = File.OpenRead(path);
338+
Assert.Throws<NotSupportedException>(() =>
339+
{
340+
_ = client.TranscribeAudioStreamingAsync(inputStream, filename);
341+
});
342+
}
343+
else if (audioSourceKind == AudioSourceKind.UsingFilePath)
344+
{
345+
Assert.Throws<NotSupportedException>(() =>
346+
{
347+
_ = client.TranscribeAudioStreamingAsync(path);
348+
});
349+
}
350+
}
325351
}

0 commit comments

Comments
 (0)