99
1010namespace OpenAI . Tests . Audio ;
1111
12- [ Parallelizable ( ParallelScope . All ) ]
1312[ Category ( "Audio" ) ]
1413public partial class TranslationTests : OpenAIRecordedTestBase
1514{
16- public TranslationTests ( bool isAsync ) : base ( isAsync )
15+ public TranslationTests ( bool isAsync ) : base ( isAsync , RecordedTestMode . Record )
1716 {
1817 }
1918
@@ -28,24 +27,27 @@ public enum AudioSourceKind
2827 [ TestCase ( AudioSourceKind . UsingFilePath ) ]
2928 public async Task TranslationWorks ( AudioSourceKind audioSourceKind )
3029 {
31- AudioClient client = GetProxiedOpenAIClient < AudioClient > ( TestScenario . Audio_Whisper ) ;
30+ using ( Recording . DisableRequestBodyRecording ( ) ) // Temp while multipart support in the test proxy is being implemented
31+ {
32+ AudioClient client = GetProxiedOpenAIClient < AudioClient > ( TestScenario . Audio_Whisper ) ;
3233
33- string filename = "audio_french.wav" ;
34- string path = Path . Combine ( "Assets" , filename ) ;
35- AudioTranslation translation = null ;
34+ string filename = "audio_french.wav" ;
35+ string path = Path . Combine ( "Assets" , filename ) ;
36+ AudioTranslation translation = null ;
3637
37- if ( audioSourceKind == AudioSourceKind . UsingStream )
38- {
39- using FileStream audio = File . OpenRead ( path ) ;
38+ if ( audioSourceKind == AudioSourceKind . UsingStream )
39+ {
40+ using FileStream audio = File . OpenRead ( path ) ;
4041
41- translation = await client . TranslateAudioAsync ( audio , filename ) ;
42- }
43- else if ( audioSourceKind == AudioSourceKind . UsingFilePath )
44- {
45- translation = await client . TranslateAudioAsync ( path ) ;
42+ translation = await client . TranslateAudioAsync ( audio , filename ) ;
43+ }
44+ else if ( audioSourceKind == AudioSourceKind . UsingFilePath )
45+ {
46+ translation = await client . TranslateAudioAsync ( path ) ;
47+ }
48+ Assert . That ( translation ? . Text , Is . Not . Null ) ;
49+ Assert . That ( translation . Text . ToLowerInvariant ( ) , Contains . Substring ( "whisper" ) ) ;
4650 }
47- Assert . That ( translation ? . Text , Is . Not . Null ) ;
48- Assert . That ( translation . Text . ToLowerInvariant ( ) , Contains . Substring ( "whisper" ) ) ;
4951 }
5052
5153 [ Test ]
@@ -57,55 +59,58 @@ public async Task TranslationWorks(AudioSourceKind audioSourceKind)
5759 [ TestCase ( null ) ]
5860 public async Task TranslationFormatsWork ( string responseFormat )
5961 {
60- AudioClient client = GetProxiedOpenAIClient < AudioClient > ( TestScenario . Audio_Whisper ) ;
61- string path = Path . Combine ( "Assets" , "audio_french.wav" ) ;
62-
63- AudioTranslationOptions options = new ( )
62+ using ( Recording . DisableRequestBodyRecording ( ) ) // Temp while multipart support in the test proxy is being implemented
6463 {
65- ResponseFormat = responseFormat switch
66- {
67- "text" => AudioTranslationFormat . Text ,
68- "json" => AudioTranslationFormat . Simple ,
69- "verbose_json" => AudioTranslationFormat . Verbose ,
70- "srt" => AudioTranslationFormat . Srt ,
71- "vtt" => AudioTranslationFormat . Vtt ,
72- _ => ( AudioTranslationFormat ? ) null
73- }
74- } ;
64+ AudioClient client = GetProxiedOpenAIClient < AudioClient > ( TestScenario . Audio_Whisper ) ;
65+ string path = Path . Combine ( "Assets" , "audio_french.wav" ) ;
7566
76- AudioTranslation translation = await client . TranslateAudioAsync ( path , options ) ;
67+ AudioTranslationOptions options = new ( )
68+ {
69+ ResponseFormat = responseFormat switch
70+ {
71+ "text" => AudioTranslationFormat . Text ,
72+ "json" => AudioTranslationFormat . Simple ,
73+ "verbose_json" => AudioTranslationFormat . Verbose ,
74+ "srt" => AudioTranslationFormat . Srt ,
75+ "vtt" => AudioTranslationFormat . Vtt ,
76+ _ => ( AudioTranslationFormat ? ) null
77+ }
78+ } ;
7779
78- Assert . That ( translation ? . Text ? . ToLowerInvariant ( ) , Does . Contain ( "recognition" ) ) ;
80+ AudioTranslation translation = await client . TranslateAudioAsync ( path , options ) ;
7981
80- if ( options . ResponseFormat == AudioTranslationFormat . Verbose )
81- {
82- Assert . That ( translation . Language , Is . EqualTo ( "english" ) ) ;
83- Assert . That ( translation . Duration , Is . GreaterThan ( TimeSpan . Zero ) ) ;
84- Assert . That ( translation . Segments , Is . Not . Empty ) ;
82+ Assert . That ( translation ? . Text ? . ToLowerInvariant ( ) , Does . Contain ( "recognition" ) ) ;
8583
86- for ( int i = 0 ; i < translation . Segments . Count ; i ++ )
84+ if ( options . ResponseFormat == AudioTranslationFormat . Verbose )
8785 {
88- TranscribedSegment segment = translation . Segments [ i ] ;
86+ Assert . That ( translation . Language , Is . EqualTo ( "english" ) ) ;
87+ Assert . That ( translation . Duration , Is . GreaterThan ( TimeSpan . Zero ) ) ;
88+ Assert . That ( translation . Segments , Is . Not . Empty ) ;
8989
90- if ( i > 0 )
90+ for ( int i = 0 ; i < translation . Segments . Count ; i ++ )
9191 {
92- Assert . That ( segment . StartTime , Is . GreaterThanOrEqualTo ( translation . Segments [ i - 1 ] . EndTime ) ) ;
93- }
92+ TranscribedSegment segment = translation . Segments [ i ] ;
93+
94+ if ( i > 0 )
95+ {
96+ Assert . That ( segment . StartTime , Is . GreaterThanOrEqualTo ( translation . Segments [ i - 1 ] . EndTime ) ) ;
97+ }
9498
95- Assert . That ( segment . Id , Is . EqualTo ( i ) ) ;
96- Assert . That ( segment . EndTime , Is . GreaterThanOrEqualTo ( segment . StartTime ) ) ;
97- Assert . That ( segment . TokenIds . Span . Length , Is . GreaterThan ( 0 ) ) ;
99+ Assert . That ( segment . Id , Is . EqualTo ( i ) ) ;
100+ Assert . That ( segment . EndTime , Is . GreaterThanOrEqualTo ( segment . StartTime ) ) ;
101+ Assert . That ( segment . TokenIds . Span . Length , Is . GreaterThan ( 0 ) ) ;
98102
99- Assert . That ( segment . AverageLogProbability , Is . LessThan ( - 0.001f ) . Or . GreaterThan ( 0.001f ) ) ;
100- Assert . That ( segment . CompressionRatio , Is . LessThan ( - 0.001f ) . Or . GreaterThan ( 0.001f ) ) ;
101- Assert . That ( segment . NoSpeechProbability , Is . LessThan ( - 0.001f ) . Or . GreaterThan ( 0.001f ) ) ;
103+ Assert . That ( segment . AverageLogProbability , Is . LessThan ( - 0.001f ) . Or . GreaterThan ( 0.001f ) ) ;
104+ Assert . That ( segment . CompressionRatio , Is . LessThan ( - 0.001f ) . Or . GreaterThan ( 0.001f ) ) ;
105+ Assert . That ( segment . NoSpeechProbability , Is . LessThan ( - 0.001f ) . Or . GreaterThan ( 0.001f ) ) ;
106+ }
107+ }
108+ else
109+ {
110+ Assert . That ( translation . Duration , Is . Null ) ;
111+ Assert . That ( translation . Language , Is . Null ) ;
112+ Assert . That ( translation . Segments , Is . Not . Null . And . Empty ) ;
102113 }
103- }
104- else
105- {
106- Assert . That ( translation . Duration , Is . Null ) ;
107- Assert . That ( translation . Language , Is . Null ) ;
108- Assert . That ( translation . Segments , Is . Not . Null . And . Empty ) ;
109114 }
110115 }
111116}
0 commit comments