Skip to content

Commit

Permalink
Refactor AudioTranscriptionController.cs to update STT API endpoint a…
Browse files Browse the repository at this point in the history
…nd improve request body serialization
  • Loading branch information
heblasco committed Sep 26, 2024
1 parent c0b522b commit f2feeb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/AIHub/Controllers/AudioTranscriptionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,23 @@ public async Task<IActionResult> TranscribeAudio(string audio_url)
// CALL 1: STT 3.1
var request = new HttpRequestMessage(HttpMethod.Post, "https://" + speechRegion + ".api.cognitive.microsoft.com/speechtotext/v3.1/transcriptions");
request.Headers.Add("Ocp-Apim-Subscription-Key", speechSubscriptionKey);
var content = new StringContent("{\r\n\"contentUrls\": [\r\n \"" + audio + "\"\r\n ],\r\n \"locale\": \"es-es\",\r\n \"displayName\": \"My Transcription\",\r\n \"model\": null,\r\n \"properties\": {\r\n \"wordLevelTimestampsEnabled\": true,\r\n \"languageIdentification\": {\r\n \"candidateLocales\": [\r\n \"en-US\", \"de-DE\", \"es-ES\"\r\n ]\r\n }\r\n }\r\n}", null, "application/json");
request.Content = content;
var requestBody = new
{
contentUrls = new[] { audio },
locale = "es-es",
displayName = "My Transcription",
model = (string?)null,
properties = new
{
wordLevelTimestampsEnabled = true,
languageIdentification = new
{
candidateLocales = new[] { "en-US", "de-DE", "es-ES" }
}
}
};
Console.WriteLine(JsonSerializer.Serialize(requestBody));
request.Content = new StringContent(JsonSerializer.Serialize(requestBody), Encoding.UTF8, "application/json");
var response = await httpClient.SendAsync(request);
response.EnsureSuccessStatusCode();
var responsejson = JsonSerializer.Deserialize<JsonObject>(await response.Content.ReadAsStringAsync())!;
Expand Down
3 changes: 2 additions & 1 deletion src/AIHub/Controllers/ImageAnalyzerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public async Task<IActionResult> DenseCaptionImage(string image_url, string prom
}
else
{
Console.WriteLine($"Error after GPT4V: {response.StatusCode}, {response.ReasonPhrase}");
var errorContent = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Error after GPT4o: {response.StatusCode}, {errorContent}");
}

return View("ImageAnalyzer", model);
Expand Down

0 comments on commit f2feeb2

Please sign in to comment.