Skip to content

Commit e81ad7f

Browse files
ATILATostaATILATosta
authored andcommitted
Error fix in integrated recognize tests
1 parent e669345 commit e81ad7f

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/IBM.WatsonDeveloperCloud.SpeechToText/v1/SpeechToTextService.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public object DeleteSession(string sessionId)
191191
return result;
192192
}
193193

194-
public SpeechRecognitionEvent Recognize(string contentType, FileStream audio, string transferEncoding = "", string model = "", string customizationId = "", bool? continuous = null, int? inactivityTimeout = null, string[] keywords = null, double? keywordsThreshold = null, int? maxAlternatives = null, double? wordAlternativesThreshold = null, bool? wordConfidence = null, bool? timestamps = null, bool profanityFilter = false, bool? smartFormatting = null, bool? speakerLabels = null)
194+
public SpeechRecognitionEvent Recognize(string contentType, FileStream audio, string transferEncoding = "", string model = "en-US_BroadbandModel", string customizationId = "", bool? continuous = null, int? inactivityTimeout = null, string[] keywords = null, double? keywordsThreshold = null, int? maxAlternatives = null, double? wordAlternativesThreshold = null, bool? wordConfidence = null, bool? timestamps = null, bool profanityFilter = false, bool? smartFormatting = null, bool? speakerLabels = null)
195195
{
196196
if (audio == null)
197197
throw new ArgumentNullException($"{nameof(audio)}");
@@ -217,7 +217,7 @@ public SpeechRecognitionEvent Recognize(string contentType, FileStream audio, st
217217
model: model);
218218
}
219219

220-
public SpeechRecognitionEvent Recognize(string contentType, Metadata metaData, FileStream audio, string transferEncoding = "", string model = "", string customizationId = "")
220+
public SpeechRecognitionEvent Recognize(string contentType, Metadata metaData, FileStream audio, string transferEncoding = "", string model = "en-US_BroadbandModel", string customizationId = "")
221221
{
222222
if (metaData == null)
223223
throw new ArgumentNullException($"{nameof(metaData)}");
@@ -235,7 +235,7 @@ public SpeechRecognitionEvent Recognize(string contentType, Metadata metaData, F
235235
model: model);
236236
}
237237

238-
public SpeechRecognitionEvent RecognizeWithSession(string sessionId, string contentType, FileStream audio, string transferEncoding = "", string model = "", string customizationId = "", bool? continuous = null, int? inactivityTimeout = null, string[] keywords = null, double? keywordsThreshold = null, int? maxAlternatives = null, double? wordAlternativesThreshold = null, bool? wordConfidence = null, bool? timestamps = null, bool profanityFilter = false, bool? smartFormatting = null, bool? speakerLabels = null)
238+
public SpeechRecognitionEvent RecognizeWithSession(string sessionId, string contentType, FileStream audio, string transferEncoding = "", string model = "en-US_BroadbandModel", string customizationId = "", bool? continuous = null, int? inactivityTimeout = null, string[] keywords = null, double? keywordsThreshold = null, int? maxAlternatives = null, double? wordAlternativesThreshold = null, bool? wordConfidence = null, bool? timestamps = null, bool profanityFilter = false, bool? smartFormatting = null, bool? speakerLabels = null)
239239
{
240240
if (string.IsNullOrEmpty(sessionId))
241241
throw new ArgumentNullException($"{nameof(sessionId)}");
@@ -264,7 +264,7 @@ public SpeechRecognitionEvent RecognizeWithSession(string sessionId, string cont
264264
model: model);
265265
}
266266

267-
public SpeechRecognitionEvent RecognizeWithSession(string sessionId, string contentType, Metadata metaData, FileStream audio, string transferEncoding = "", string model = "", string customizationId = "")
267+
public SpeechRecognitionEvent RecognizeWithSession(string sessionId, string contentType, Metadata metaData, FileStream audio, string transferEncoding = "", string model = "en-US_BroadbandModel", string customizationId = "")
268268
{
269269
if (string.IsNullOrEmpty(sessionId))
270270
throw new ArgumentNullException($"{nameof(sessionId)}");
@@ -307,13 +307,15 @@ private SpeechRecognitionEvent Recognize(string sessionId, string contentType, M
307307
{
308308
request =
309309
this.Client.WithAuthentication(this.UserName, this.Password)
310-
.PostAsync($"{this.Endpoint}{string.Format(PATH_SESSION_RECOGNIZE, sessionId)}");
311-
//.WithHeader("Cookie", sessionId);
310+
.PostAsync($"{this.Endpoint}{string.Format(PATH_SESSION_RECOGNIZE, sessionId)}")
311+
.WithHeader("Cookie", sessionId);
312312
}
313313

314314
if (metaData == null)
315315
{
316-
request.WithArgument("model", model);
316+
// if a session exists, the model should not be sent
317+
if (string.IsNullOrEmpty(sessionId))
318+
request.WithArgument("model", model);
317319

318320
if (!string.IsNullOrEmpty(customizationId))
319321
request.WithArgument("customization_id", customizationId);
@@ -351,9 +353,7 @@ private SpeechRecognitionEvent Recognize(string sessionId, string contentType, M
351353
if (speakerLabels.HasValue)
352354
request.WithArgument("speaker_labels", speakerLabels.Value);
353355

354-
//StreamContent bodyContent = new StreamContent(audio);
355-
ByteArrayContent bodyContent = new ByteArrayContent(audio.ReadAllBytes());
356-
356+
StreamContent bodyContent = new StreamContent(audio);
357357
bodyContent.Headers.Add("Content-Type", contentType);
358358

359359
request.WithBodyContent(bodyContent);
@@ -366,11 +366,14 @@ private SpeechRecognitionEvent Recognize(string sessionId, string contentType, M
366366
metadata.Headers.ContentType = MediaTypeHeaderValue.Parse(HttpMediaType.APPLICATION_JSON);
367367

368368
var audioContent = new ByteArrayContent((audio as Stream).ReadAllBytes());
369-
//var audioContent = new StreamContent((audio as Stream));
370369
audioContent.Headers.ContentType = MediaTypeHeaderValue.Parse(contentType);
371370

372371
MultipartFormDataContent formData = new MultipartFormDataContent();
373-
request.WithArgument("model", model);
372+
373+
// if a session exists, the model should not be sent
374+
if (string.IsNullOrEmpty(sessionId))
375+
request.WithArgument("model", model);
376+
374377
formData.Add(metadata, "metadata");
375378
formData.Add(audioContent, "upload", Path.GetFileName(audio.Name));
376379

@@ -401,7 +404,7 @@ public List<SpeechRecognitionEvent> ObserveResult(string sessionId, int? sequenc
401404
{
402405
var request =
403406
this.Client.WithAuthentication(this.UserName, this.Password)
404-
.PostAsync($"{this.Endpoint}{string.Format(PATH_OBSERVE_RESULT, sessionId)}");
407+
.GetAsync($"{this.Endpoint}{string.Format(PATH_OBSERVE_RESULT, sessionId)}");
405408

406409
if (sequenceId.HasValue)
407410
request.WithArgument("sequence_id", sequenceId);

test/IBM.WatsonDeveloperCloud.SpeechToText.IntegrationTests/SpeechToTextServiceIntegrationTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public void t05_Recognize_BodyContent_Sucess()
133133
File.OpenRead(@"Assets\test-audio.wav");
134134

135135
var results =
136-
service.Recognize(audio.GetMediaTypeFromFile(), audio, "", "en-US_BroadbandModel");
136+
service.Recognize(audio.GetMediaTypeFromFile(), audio, "");
137137

138138
Assert.IsNotNull(results);
139139
Assert.IsNotNull(results.Results);
@@ -245,7 +245,7 @@ public void t09_ObserveResult_Success()
245245
service.RecognizeWithSession(session.SessionId, audio.GetMediaTypeFromFile(), metadata, audio, "", modelName);
246246

247247
var results =
248-
service.ObserveResult(session.SessionId);
248+
service.ObserveResult(session.SessionId, interimResults: true);
249249

250250
Assert.IsNotNull(results);
251251
Assert.IsTrue(results.Count > 0);

0 commit comments

Comments
 (0)