Skip to content

Commit 5612f86

Browse files
committed
fix: edit isBrowser to explicitly check for a window.document before dismissing it as not browser
1 parent b62f2e3 commit 5612f86

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { require } from "https://deno.land/x/require/mod.ts";
2+
import { dirname } from "https://deno.land/std/path/mod.ts";
3+
import { fileURLToPath } from "https://deno.land/std@0.177.0/node/url.ts";
4+
5+
const __dirname = dirname(fileURLToPath(import.meta.url));
6+
7+
const { createClient } = require("../../dist/module/index.js");
8+
9+
const transcribeUrl = async () => {
10+
const deepgram = createClient(Deno.env.get("DEEPGRAM_API_KEY"));
11+
12+
console.log("Transcribing URL", "https://dpgr.am/spacewalk.wav");
13+
const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
14+
{
15+
url: "https://dpgr.am/spacewalk.wav",
16+
},
17+
{
18+
model: "nova-2",
19+
}
20+
);
21+
22+
if (error) console.error(error);
23+
if (!error) console.dir(result, { depth: 1 });
24+
};
25+
26+
const transcribeFile = async () => {
27+
const deepgram = createClient(Deno.env.get("DEEPGRAM_API_KEY"));
28+
29+
const filePath = path.join(__dirname, "../spacewalk.wav");
30+
console.log(filePath);
31+
const file = await Deno.readFile(filePath);
32+
33+
console.log("Transcribing file", file);
34+
const { result, error } = await deepgram.listen.prerecorded.transcribeFile(file, {
35+
model: "nova-2",
36+
});
37+
38+
if (error) console.error(error);
39+
if (!error) console.dir(result, { depth: 1 });
40+
};
41+
42+
transcribeUrl();
43+
transcribeFile();

src/lib/helpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ export function stripTrailingSlash(url: string): string {
1616
return url.replace(/\/$/, "");
1717
}
1818

19-
export const isBrowser = () => typeof window !== "undefined";
20-
export const isServer = () => typeof process !== "undefined";
19+
export function isBrowser() {
20+
return typeof window !== "undefined" && typeof window.document !== "undefined";
21+
}
2122

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

0 commit comments

Comments
 (0)