Skip to content

Commit

Permalink
fix: redorder language tabs on summarization page
Browse files Browse the repository at this point in the history
  • Loading branch information
a-dinoto committed Mar 4, 2025
1 parent 9694e67 commit 7c79029
Showing 1 changed file with 145 additions and 145 deletions.
290 changes: 145 additions & 145 deletions fern/pages/03-audio-intelligence/summarization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ You can only enable one of the Summarization and [Auto Chapters](/docs/audio-int


<Tabs groupId="language">
<Tab language="python" title="Python SDK" default>
<Tab language="python-sdk" title="Python SDK" default>

Enable Summarization by setting `summarization` to `True` in the transcription config. Use `summary_model` and `summary_type` to change the summary format.

Expand Down Expand Up @@ -110,7 +110,7 @@ while True:
```

</Tab>
<Tab language="typescript" title="TypeScript SDK">
<Tab language="typescript-sdk" title="TypeScript SDK">

Enable Summarization by setting `summarization` to `true` in the transcription config. Use `summary_model` and `summary_type` to change the summary format.

Expand Down Expand Up @@ -205,87 +205,110 @@ while (true) {
```

</Tab>
<Tab language="php" title="PHP">
<Tab language="csharp" title="C#">

Enable Summarization by setting `summarization` to `true` in the JSON payload. Use `summary_model` and `summary_type` to change the summary format.
Enable `summarization` in the transcription parameters. Use `summary_model` and `summary_type` to change the summary format.

If you specify one of `summary_model` or `summary_type`, then you must specify the other.
If you specify one of `summary_model` and `summary_type`, then you must specify the other.

The following example returns an informative summary in a bulleted list.

```php {30-32}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$base_url = "https://api.assemblyai.com";

$headers = array(
"authorization: d8a377b7d8fd4a4ca74c6bd875bdf015",
"content-type: application/json"
);

$path = "audio files/audio05853.wav";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $base_url . "/v2/upload");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($path));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
<Info>
Most of these libraries are included by default, but on .NET Framework and Mono you need to reference the System.Net.Http library and install the [System.Net.Http.Json NuGet package](https://www.nuget.org/packages/System.Net.Http.Json).
</Info>

$response = curl_exec($ch);
$response_data = json_decode($response, true);
$upload_url = $response_data["upload_url"];
```csharp {34}
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

curl_close($ch);
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("<YOUR_API_KEY>");
}

$data = array(
"audio_url" => $upload_url, // You can also use a URL to an audio or video file on the web
"summarization" => true,
"summary_model" => "informative",
"summary_type" => "bullets"
);
private static async Task<string> UploadFileAsync(string filePath, HttpClient httpClient)
{
using (var fileStream = File.OpenRead(filePath))
using (var fileContent = new StreamContent(fileStream))
{
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

$url = $base_url . "/v2/transcript";
$curl = curl_init($url);
using (var response = await httpClient.PostAsync("https://api.assemblyai.com/v2/upload", fileContent))
{
response.EnsureSuccessStatusCode();
var jsonDoc = await response.Content.ReadFromJsonAsync<JsonDocument>();
return jsonDoc.RootElement.GetProperty("upload_url").GetString();
}
}
}

curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
private static async Task<Transcript> CreateTranscriptAsync(string audioUrl, HttpClient httpClient)
{
var data = new { audio_url = audioUrl, summarization = true, summary_model = "informative", summary_type = "bullets" };
var content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json");

$response = curl_exec($curl);
using (var response = await httpClient.PostAsync("https://api.assemblyai.com/v2/transcript", content))
{
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<Transcript>();
}
}

$response = json_decode($response, true);
public class Transcript
{
public string Id { get; set; }
public string Status { get; set; }
public string Text { get; set; }

curl_close($curl);
[JsonPropertyName("language_code")]
public string LanguageCode { get; set; }

$transcript_id = $response['id'];
echo "Transcript ID: $transcript_id\n";
public string Error { get; set; }
}

$polling_endpoint = "https://api.assemblyai.com/v2/transcript/" . $transcript_id;
private static async Task<Transcript> WaitForTranscriptToProcess(Transcript transcript, HttpClient httpClient)
{
var pollingEndpoint = $"https://api.assemblyai.com/v2/transcript/{transcript.Id}";

while (true) {
$polling_response = curl_init($polling_endpoint);
while (true)
{
var pollingResponse = await httpClient.GetAsync(pollingEndpoint);
transcript = await pollingResponse.Content.ReadFromJsonAsync<Transcript>();
switch (transcript.Status)
{
case "processing":
case "queued":
await Task.Delay(TimeSpan.FromSeconds(3));
break;
case "completed":
return transcript;
case "error":
throw new Exception($"Transcription failed: {transcript.Error}");
default:
throw new Exception("This code shouldn't be reachable.");
}
}
}

curl_setopt($polling_response, CURLOPT_HTTPHEADER, $headers);
curl_setopt($polling_response, CURLOPT_RETURNTRANSFER, true);
using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("<YOUR_API_KEY>");

$transcription_result = json_decode(curl_exec($polling_response), true);
var uploadUrl = await UploadFileAsync("/my_audio.mp3", httpClient);
var transcript = await CreateTranscriptAsync(uploadUrl, httpClient);
transcript = await WaitForTranscriptToProcess(transcript, httpClient);

if ($transcription_result['status'] === "completed") {
echo $transcription_result['summary'];
break;
} else if ($transcription_result['status'] === "error") {
throw new Exception("Transcription failed: " . $transcription_result['error']);
} else {
sleep(3);
}
Console.WriteLine(transcript.Summary);
}
```

</Tab>
<Tab language="ruby" title="Ruby">

Expand Down Expand Up @@ -363,110 +386,87 @@ end
```

</Tab>
<Tab language="csharp" title="C#">
<Tab language="php" title="PHP">

Enable `summarization` in the transcription parameters. Use `summary_model` and `summary_type` to change the summary format.
Enable Summarization by setting `summarization` to `true` in the JSON payload. Use `summary_model` and `summary_type` to change the summary format.

If you specify one of `summary_model` and `summary_type`, then you must specify the other.
If you specify one of `summary_model` or `summary_type`, then you must specify the other.

The following example returns an informative summary in a bulleted list.

<Info>
Most of these libraries are included by default, but on .NET Framework and Mono you need to reference the System.Net.Http library and install the [System.Net.Http.Json NuGet package](https://www.nuget.org/packages/System.Net.Http.Json).
</Info>
```php {30-32}
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

```csharp {34}
using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
$base_url = "https://api.assemblyai.com";

using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("<YOUR_API_KEY>");
}
$headers = array(
"authorization: d8a377b7d8fd4a4ca74c6bd875bdf015",
"content-type: application/json"
);

private static async Task<string> UploadFileAsync(string filePath, HttpClient httpClient)
{
using (var fileStream = File.OpenRead(filePath))
using (var fileContent = new StreamContent(fileStream))
{
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
$path = "audio files/audio05853.wav";

using (var response = await httpClient.PostAsync("https://api.assemblyai.com/v2/upload", fileContent))
{
response.EnsureSuccessStatusCode();
var jsonDoc = await response.Content.ReadFromJsonAsync<JsonDocument>();
return jsonDoc.RootElement.GetProperty("upload_url").GetString();
}
}
}
$ch = curl_init();

private static async Task<Transcript> CreateTranscriptAsync(string audioUrl, HttpClient httpClient)
{
var data = new { audio_url = audioUrl, summarization = true, summary_model = "informative", summary_type = "bullets" };
var content = new StringContent(JsonSerializer.Serialize(data), Encoding.UTF8, "application/json");
curl_setopt($ch, CURLOPT_URL, $base_url . "/v2/upload");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($path));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

using (var response = await httpClient.PostAsync("https://api.assemblyai.com/v2/transcript", content))
{
response.EnsureSuccessStatusCode();
return await response.Content.ReadFromJsonAsync<Transcript>();
}
}
$response = curl_exec($ch);
$response_data = json_decode($response, true);
$upload_url = $response_data["upload_url"];

public class Transcript
{
public string Id { get; set; }
public string Status { get; set; }
public string Text { get; set; }
curl_close($ch);

[JsonPropertyName("language_code")]
public string LanguageCode { get; set; }
$data = array(
"audio_url" => $upload_url, // You can also use a URL to an audio or video file on the web
"summarization" => true,
"summary_model" => "informative",
"summary_type" => "bullets"
);

public string Error { get; set; }
}
$url = $base_url . "/v2/transcript";
$curl = curl_init($url);

private static async Task<Transcript> WaitForTranscriptToProcess(Transcript transcript, HttpClient httpClient)
{
var pollingEndpoint = $"https://api.assemblyai.com/v2/transcript/{transcript.Id}";
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

while (true)
{
var pollingResponse = await httpClient.GetAsync(pollingEndpoint);
transcript = await pollingResponse.Content.ReadFromJsonAsync<Transcript>();
switch (transcript.Status)
{
case "processing":
case "queued":
await Task.Delay(TimeSpan.FromSeconds(3));
break;
case "completed":
return transcript;
case "error":
throw new Exception($"Transcription failed: {transcript.Error}");
default:
throw new Exception("This code shouldn't be reachable.");
}
}
}
$response = curl_exec($curl);

using (var httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("<YOUR_API_KEY>");
$response = json_decode($response, true);

var uploadUrl = await UploadFileAsync("/my_audio.mp3", httpClient);
var transcript = await CreateTranscriptAsync(uploadUrl, httpClient);
transcript = await WaitForTranscriptToProcess(transcript, httpClient);
curl_close($curl);

Console.WriteLine(transcript.Summary);
$transcript_id = $response['id'];
echo "Transcript ID: $transcript_id\n";

$polling_endpoint = "https://api.assemblyai.com/v2/transcript/" . $transcript_id;

while (true) {
$polling_response = curl_init($polling_endpoint);

curl_setopt($polling_response, CURLOPT_HTTPHEADER, $headers);
curl_setopt($polling_response, CURLOPT_RETURNTRANSFER, true);

$transcription_result = json_decode(curl_exec($polling_response), true);

if ($transcription_result['status'] === "completed") {
echo $transcription_result['summary'];
break;
} else if ($transcription_result['status'] === "error") {
throw new Exception("Transcription failed: " . $transcription_result['error']);
} else {
sleep(3);
}
}
```

</Tab>
</Tabs>

Expand Down

0 comments on commit 7c79029

Please sign in to comment.