@@ -17,6 +17,7 @@ public class BingSpeechApiClient
17
17
const int ChunkSize = 1024 ;
18
18
const int DefaultChannelCount = 1 ;
19
19
const int DefaultBitsPerSample = 16 ;
20
+
20
21
readonly string subscriptionKey ;
21
22
readonly HttpClient client ;
22
23
@@ -28,7 +29,6 @@ public class BingSpeechApiClient
28
29
/// <value>The auth client.</value>
29
30
AuthenticationClient AuthClient { get ; set ; }
30
31
31
-
32
32
/// <summary>
33
33
/// Gets or sets the endpoint used to get the authentication token for the Speech API.
34
34
/// </summary>
@@ -38,21 +38,18 @@ public class BingSpeechApiClient
38
38
/// </remarks>
39
39
public Endpoint AuthEndpoint { get ; set ; } = Endpoints . Authentication ;
40
40
41
-
42
41
/// <summary>
43
42
/// Gets and sets the <see cref="AuthenticationMode"/> used by the the speech client.
44
43
/// </summary>
45
44
public AuthenticationMode AuthenticationMode { get ; set ; }
46
45
47
-
48
46
/// <summary>
49
47
/// Gets or sets the endpoint used to talk to the Speech API.
50
48
/// </summary>
51
49
/// <value>The endpoint.</value>
52
50
/// <remarks>Defaults to <see cref="Endpoints.BingSpeechApi"/>. To use a CRIS/Custom Speech Service endpoint, set this to a new <see cref="Endpoint"/> with the details for your CRIS service.</remarks>
53
51
public Endpoint SpeechEndpoint { get ; set ; } = Endpoints . BingSpeechApi ;
54
52
55
-
56
53
/// <summary>
57
54
/// Gets or sets the Recognition language.
58
55
/// </summary>
@@ -62,7 +59,6 @@ public class BingSpeechApiClient
62
59
/// </remarks>
63
60
public string RecognitionLanguage { get ; set ; } = "en-US" ;
64
61
65
-
66
62
/// <summary>
67
63
/// Gets or sets the recognition mode.
68
64
/// </summary>
@@ -75,7 +71,6 @@ public class BingSpeechApiClient
75
71
/// </remarks>
76
72
public RecognitionMode RecognitionMode { get ; set ; }
77
73
78
-
79
74
/// <summary>
80
75
/// Gets or sets the profanity mode.
81
76
/// </summary>
@@ -86,14 +81,12 @@ public class BingSpeechApiClient
86
81
/// </remarks>
87
82
public ProfanityMode ProfanityMode { get ; set ; }
88
83
89
-
90
84
/// <summary>
91
85
/// Gets or sets the API version.
92
86
/// </summary>
93
87
/// <value>The API version. Defaults to "v1"</value>
94
88
public string ApiVersion { get ; set ; } = "v1" ;
95
89
96
-
97
90
/// <summary>
98
91
/// Initializes a new instance of the <see cref="T:Xamarin.Cognitive.BingSpeech.BingSpeechApiClient"/> class.
99
92
/// </summary>
@@ -106,7 +99,6 @@ public BingSpeechApiClient (string subscriptionKey)
106
99
AuthClient = new AuthenticationClient ( AuthEndpoint , subscriptionKey ) ;
107
100
}
108
101
109
-
110
102
/// <summary>
111
103
/// Calls to the <see cref="AuthEndpoint"/> authentication endpoint to get a JWT token for authentication to the Bing Speech API. Token is cached and valid for 10 minutes.
112
104
/// </summary>
@@ -117,7 +109,6 @@ public async Task AuthenticateWithToken (bool forceNewToken = false)
117
109
await AuthClient . Authenticate ( forceNewToken ) ;
118
110
}
119
111
120
-
121
112
/// <summary>
122
113
/// Clears any cached auth token.
123
114
/// </summary>
@@ -126,7 +117,6 @@ public void ClearAuthToken ()
126
117
AuthClient . ClearToken ( ) ;
127
118
}
128
119
129
-
130
120
HttpRequestMessage CreateRequest ( OutputMode outputMode )
131
121
{
132
122
try
@@ -170,7 +160,6 @@ HttpRequestMessage CreateRequest (OutputMode outputMode)
170
160
}
171
161
}
172
162
173
-
174
163
async Task < string > SendRequest ( Func < HttpRequestMessage > requestFactory , Func < HttpContent > contentFactory )
175
164
{
176
165
try
@@ -219,7 +208,6 @@ async Task<string> SendRequest (Func<HttpRequestMessage> requestFactory, Func<Ht
219
208
throw new Exception ( "SendRequest: Unable to send successful request - unknown error or null response received" ) ;
220
209
}
221
210
222
-
223
211
HttpContent CopyRequestContent ( HttpContent content )
224
212
{
225
213
return new PushStreamContent ( async ( outputStream , httpContext , transportContext ) =>
@@ -257,7 +245,6 @@ HttpContent CopyRequestContent (HttpContent content)
257
245
} , new MediaTypeHeaderValue ( Constants . MimeTypes . WavAudio ) ) ;
258
246
}
259
247
260
-
261
248
HttpContent PopulateRequestContent ( string audioFilePath )
262
249
{
263
250
return new PushStreamContent ( async ( outputStream , httpContext , transportContext ) =>
@@ -289,7 +276,6 @@ HttpContent PopulateRequestContent (string audioFilePath)
289
276
} , new MediaTypeHeaderValue ( Constants . MimeTypes . WavAudio ) ) ;
290
277
}
291
278
292
-
293
279
HttpContent PopulateRequestContent ( Stream audioStream , int ? channelCount = null , int ? sampleRate = null , int ? bitsPerSample = null , Task recordingTask = null , int streamReadDelay = 30 )
294
280
{
295
281
const int audioDataWaitInterval = 100 ; //ms
@@ -366,7 +352,6 @@ HttpContent PopulateRequestContent (Stream audioStream, int? channelCount = null
366
352
} , new MediaTypeHeaderValue ( Constants . MimeTypes . WavAudio ) ) ;
367
353
}
368
354
369
-
370
355
/// <summary>
371
356
/// Returns Speech to Text results for the given audio input. Begins sending the audio stream to the server immediately.
372
357
/// </summary>
@@ -407,7 +392,6 @@ public async Task<RecognitionSpeechResult> SpeechToTextSimple (string audioFileP
407
392
}
408
393
}
409
394
410
-
411
395
/// <summary>
412
396
/// Returns Speech to Text results for the given audio input. Assumes the audio stream already contains a WAV file/RIFF header and WILL NOT write one.
413
397
/// </summary>
@@ -422,7 +406,6 @@ public Task<RecognitionSpeechResult> SpeechToTextSimple (Stream audioStream, Tas
422
406
return SpeechToTextSimple ( audioStream , null , null , null , recordingTask ) ;
423
407
}
424
408
425
-
426
409
/// <summary>
427
410
/// Returns Speech to Text results for the given audio input. Assumes single channel (mono) audio at 16 bits per sample and will write a WAV/RIFF header to the output stream accordingly.
428
411
/// </summary>
@@ -438,7 +421,6 @@ public Task<RecognitionSpeechResult> SpeechToTextSimple (Stream audioStream, int
438
421
return SpeechToTextSimple ( audioStream , sampleRate , DefaultChannelCount , DefaultBitsPerSample , recordingTask : recordingTask ) ;
439
422
}
440
423
441
-
442
424
/// <summary>
443
425
/// Returns Speech to Text results for the given audio input. Will write a WAV/RIFF header to the output stream with the audio details provided.
444
426
/// If ANY audio details are passed in with a null value, a RIFF header will not be written.
@@ -479,7 +461,6 @@ public async Task<RecognitionSpeechResult> SpeechToTextSimple (Stream audioStrea
479
461
}
480
462
}
481
463
482
-
483
464
/// <summary>
484
465
/// Returns Speech to Text results for the given audio input.
485
466
/// </summary>
@@ -515,7 +496,6 @@ public async Task<RecognitionResult> SpeechToTextDetailed (string audioFilePath)
515
496
}
516
497
}
517
498
518
-
519
499
/// <summary>
520
500
/// Returns Speech to Text results for the given audio input. Assumes the audio stream already contains a WAV file/RIFF header and WILL NOT write one.
521
501
/// </summary>
@@ -530,7 +510,6 @@ public Task<RecognitionResult> SpeechToTextDetailed (Stream audioStream, Task re
530
510
return SpeechToTextDetailed ( audioStream , null , null , null , recordingTask ) ;
531
511
}
532
512
533
-
534
513
/// <summary>
535
514
/// Returns Speech to Text results for the given audio input. Assumes single channel (mono) audio at 16 bits per sample and will write a WAV/RIFF header to the output stream accordingly.
536
515
/// </summary>
@@ -546,7 +525,6 @@ public Task<RecognitionResult> SpeechToTextDetailed (Stream audioStream, int sam
546
525
return SpeechToTextDetailed ( audioStream , sampleRate , DefaultChannelCount , DefaultBitsPerSample , recordingTask ) ;
547
526
}
548
527
549
-
550
528
/// <summary>
551
529
/// Returns Speech to Text results for the given audio input. Will write a WAV/RIFF header to the output stream with the audio details provided.
552
530
/// If ANY audio details are passed in with a null value, a RIFF header will not be written.
0 commit comments