Sample code for 30+ languages & platforms
Zig

VoiceBase -- Retrieve Plain Text Transcript

See more VoiceBase Examples

Retrieves a plain text transcript for a media file.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This example assumes the Chilkat HTTP API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Insert your Bearer token here:
    const access_token = "VOICEBASE_TOKEN";

    const http = try chilkat.Http.init();
    defer http.deinit();

    // Add the access (bearer) token to the request, which is a header
    // having the following format:
    // Authorization: Bearer <userAccessToken>
    const sb_auth = try chilkat.StringBuilder.init();
    defer sb_auth.deinit();
    sb_auth.append("Bearer ") catch {};
    sb_auth.append(access_token) catch {};
    http.setRequestHeader("Authorization", try sb_auth.getAsString(alloc));

    const sb_url = try chilkat.StringBuilder.init();
    defer sb_url.deinit();
    sb_url.append("https://apis.voicebase.com/v2-beta/media/$MEDIA_ID/transcripts/latest") catch {};
    _ = sb_url.replace("$MEDIA_ID", "f9b9bb88-d52c-4960-bcef-d516a9f85594");

    http.setAccept("text/plain");

    const str_text = http.quickGetStr(alloc, try sb_url.getAsString(alloc)) catch {
        std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Response status code = {d}\n", .{http.getLastStatus()});
    std.debug.print("{s}\n", .{str_text});

    if (http.getLastStatus() != 200) {
        std.debug.print("Failed\n", .{});
    } else {
        std.debug.print("Success\n", .{});
    }
}