Skip to content

Commit f2feeb2

Browse files
committed
Refactor AudioTranscriptionController.cs to update STT API endpoint and improve request body serialization
1 parent c0b522b commit f2feeb2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/AIHub/Controllers/AudioTranscriptionController.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,23 @@ public async Task<IActionResult> TranscribeAudio(string audio_url)
3838
// CALL 1: STT 3.1
3939
var request = new HttpRequestMessage(HttpMethod.Post, "https://" + speechRegion + ".api.cognitive.microsoft.com/speechtotext/v3.1/transcriptions");
4040
request.Headers.Add("Ocp-Apim-Subscription-Key", speechSubscriptionKey);
41-
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");
42-
request.Content = content;
41+
var requestBody = new
42+
{
43+
contentUrls = new[] { audio },
44+
locale = "es-es",
45+
displayName = "My Transcription",
46+
model = (string?)null,
47+
properties = new
48+
{
49+
wordLevelTimestampsEnabled = true,
50+
languageIdentification = new
51+
{
52+
candidateLocales = new[] { "en-US", "de-DE", "es-ES" }
53+
}
54+
}
55+
};
56+
Console.WriteLine(JsonSerializer.Serialize(requestBody));
57+
request.Content = new StringContent(JsonSerializer.Serialize(requestBody), Encoding.UTF8, "application/json");
4358
var response = await httpClient.SendAsync(request);
4459
response.EnsureSuccessStatusCode();
4560
var responsejson = JsonSerializer.Deserialize<JsonObject>(await response.Content.ReadAsStringAsync())!;

src/AIHub/Controllers/ImageAnalyzerController.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ public async Task<IActionResult> DenseCaptionImage(string image_url, string prom
104104
}
105105
else
106106
{
107-
Console.WriteLine($"Error after GPT4V: {response.StatusCode}, {response.ReasonPhrase}");
107+
var errorContent = await response.Content.ReadAsStringAsync();
108+
Console.WriteLine($"Error after GPT4o: {response.StatusCode}, {errorContent}");
108109
}
109110

110111
return View("ImageAnalyzer", model);

0 commit comments

Comments
 (0)