Skip to content

Commit

Permalink
fix: edit isBrowser to explicitly check for a window.document before …
Browse files Browse the repository at this point in the history
…dismissing it as not browser
  • Loading branch information
lukeocodes committed Jul 2, 2024
1 parent fd716be commit a1995a4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
43 changes: 43 additions & 0 deletions examples/disabled_deno-prerecorded/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { require } from "https://deno.land/x/require/mod.ts";
import { dirname } from "https://deno.land/std/path/mod.ts";
import { fileURLToPath } from "https://deno.land/[email protected]/node/url.ts";

const __dirname = dirname(fileURLToPath(import.meta.url));

const { createClient } = require("../../dist/module/index.js");

const transcribeUrl = async () => {
const deepgram = createClient(Deno.env.get("DEEPGRAM_API_KEY"));

console.log("Transcribing URL", "https://dpgr.am/spacewalk.wav");
const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
{
url: "https://dpgr.am/spacewalk.wav",
},
{
model: "nova-2",
}
);

if (error) console.error(error);
if (!error) console.dir(result, { depth: 1 });
};

const transcribeFile = async () => {
const deepgram = createClient(Deno.env.get("DEEPGRAM_API_KEY"));

const filePath = path.join(__dirname, "../spacewalk.wav");
console.log(filePath);
const file = await Deno.readFile(filePath);

console.log("Transcribing file", file);
const { result, error } = await deepgram.listen.prerecorded.transcribeFile(file, {
model: "nova-2",
});

if (error) console.error(error);
if (!error) console.dir(result, { depth: 1 });
};

transcribeUrl();
transcribeFile();
5 changes: 3 additions & 2 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export function stripTrailingSlash(url: string): string {
return url.replace(/\/$/, "");
}

export const isBrowser = () => typeof window !== "undefined";
export const isServer = () => typeof process !== "undefined";
export function isBrowser() {
return typeof window !== "undefined" && typeof window.document !== "undefined";
}

export function applyDefaults<O, S>(options: Partial<O> = {}, subordinate: Partial<S> = {}): S {
return merge(subordinate, options);
Expand Down

0 comments on commit a1995a4

Please sign in to comment.