0
Transcribe audio
One script reply has been approved by the moderators Verified

Create a transcript from a media file that is accessible via a URL.

Created by hugo697 32 days ago Viewed 3074 times
0
Submitted by hugo697 Bun
Verified 32 days ago
1
//native
2
type Assemblyai = {
3
  apiKey: string;
4
};
5
/**
6
 * Transcribe audio
7
 * Create a transcript from a media file that is accessible via a URL.
8
 */
9
export async function main(
10
  auth: Assemblyai,
11
  body: { audio_url: string } & {
12
    language_code?: string;
13
    language_detection?: false | true;
14
    language_confidence_threshold?: number;
15
    speech_model?: "best" | "nano";
16
    punctuate?: false | true;
17
    format_text?: false | true;
18
    disfluencies?: false | true;
19
    multichannel?: false | true;
20
    dual_channel?: false | true;
21
    webhook_url?: string;
22
    webhook_auth_header_name?: string;
23
    webhook_auth_header_value?: string;
24
    auto_highlights?: false | true;
25
    audio_start_from?: number;
26
    audio_end_at?: number;
27
    word_boost?: string[];
28
    boost_param?: "low" | "default" | "high";
29
    filter_profanity?: false | true;
30
    redact_pii?: false | true;
31
    redact_pii_audio?: false | true;
32
    redact_pii_audio_quality?: "mp3" | "wav";
33
    redact_pii_policies?:
34
      | "account_number"
35
      | "banking_information"
36
      | "blood_type"
37
      | "credit_card_cvv"
38
      | "credit_card_expiration"
39
      | "credit_card_number"
40
      | "date"
41
      | "date_interval"
42
      | "date_of_birth"
43
      | "drivers_license"
44
      | "drug"
45
      | "duration"
46
      | "email_address"
47
      | "event"
48
      | "filename"
49
      | "gender_sexuality"
50
      | "healthcare_number"
51
      | "injury"
52
      | "ip_address"
53
      | "language"
54
      | "location"
55
      | "marital_status"
56
      | "medical_condition"
57
      | "medical_process"
58
      | "money_amount"
59
      | "nationality"
60
      | "number_sequence"
61
      | "occupation"
62
      | "organization"
63
      | "passport_number"
64
      | "password"
65
      | "person_age"
66
      | "person_name"
67
      | "phone_number"
68
      | "physical_attribute"
69
      | "political_affiliation"
70
      | "religion"
71
      | "statistics"
72
      | "time"
73
      | "url"
74
      | "us_social_security_number"
75
      | "username"
76
      | "vehicle_id"
77
      | "zodiac_sign"[];
78
    redact_pii_sub?: "entity_name" | "hash";
79
    speaker_labels?: false | true;
80
    speakers_expected?: number;
81
    content_safety?: false | true;
82
    content_safety_confidence?: number;
83
    iab_categories?: false | true;
84
    custom_spelling?: { from: string[]; to: string }[];
85
    sentiment_analysis?: false | true;
86
    auto_chapters?: false | true;
87
    entity_detection?: false | true;
88
    speech_threshold?: number;
89
    summarization?: false | true;
90
    summary_model?: "informative" | "conversational" | "catchy";
91
    summary_type?:
92
      | "bullets"
93
      | "bullets_verbose"
94
      | "gist"
95
      | "headline"
96
      | "paragraph";
97
    custom_topics?: false | true;
98
    topics?: string[];
99
  },
100
) {
101
  const url = new URL(`https://api.assemblyai.com/v2/transcript`);
102

103
  const response = await fetch(url, {
104
    method: "POST",
105
    headers: {
106
      "Content-Type": "application/json",
107
      Authorization: "Bearer " + auth.apiKey,
108
    },
109
    body: JSON.stringify(body),
110
  });
111
  if (!response.ok) {
112
    const text = await response.text();
113
    throw new Error(`${response.status} ${text}`);
114
  }
115
  return await response.json();
116
}
117