-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1714ef
commit 1b38634
Showing
5 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[package] | ||
name = "deno-audio" | ||
name = "deno_audio" | ||
version = "0.1.0" | ||
authors = ["divy-work <[email protected]>"] | ||
edition = "2018" | ||
|
@@ -14,4 +14,4 @@ rodio = "0.12.0" | |
serde = { version = "1.0", features = ["derive"] } | ||
serde_json = "1.0" | ||
futures = "0.3.4" | ||
deno_core = "0.66.0" | ||
deno_core = "0.61.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
export default function filename(filenameBase: string): string { | ||
let filenameSuffix = ".so"; | ||
let filenamePrefix = "lib"; | ||
|
||
if (Deno.build.os === "windows") { | ||
filenameSuffix = ".dll"; | ||
filenamePrefix = ""; | ||
} | ||
if (Deno.build.os === "darwin") { | ||
filenameSuffix = ".dylib"; | ||
} | ||
|
||
return `${filenamePrefix}${filenameBase}${filenameSuffix}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import filename from "./detect.ts"; | ||
import { prepare } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
// @ts-ignore | ||
export const core = Deno.core as { | ||
ops: () => { [key: string]: number }; | ||
setAsyncHandler(rid: number, handler: (response: Uint8Array) => void): void; | ||
dispatch( | ||
rid: number, | ||
msg?: any, | ||
buf?: ArrayBufferView, | ||
): Uint8Array | undefined; | ||
}; | ||
|
||
const { filenameBase, pluginBase } = { | ||
"filenameBase": "deno_audio", | ||
"pluginBase": | ||
"https://github.com/littledivy/deno_audio/releases/latest/download", | ||
}; | ||
|
||
const isDev = Deno.env.get("DEV"); | ||
|
||
if (isDev) { | ||
// This will be checked against open resources after Plugin.close() | ||
// in runTestClose() below. | ||
const resourcesPre = Deno.resources(); | ||
|
||
const rid = Deno.openPlugin("./target/debug/" + filename(filenameBase)); | ||
} else { | ||
// logger.info(`Downloading latest Autopilot release from Github`); | ||
const pluginId = await prepare({ | ||
name: "deno_audio", | ||
urls: { | ||
darwin: `${pluginBase}/libdeno_audio.dylib`, | ||
windows: `${pluginBase}/deno_audio.dll`, | ||
linux: `${pluginBase}/libdeno_audio.so`, | ||
}, | ||
}); | ||
} | ||
|
||
|
||
const { | ||
play, | ||
} = core.ops(); | ||
|
||
const textDecoder = new TextDecoder(); | ||
const decoder = new TextDecoder(); | ||
|
||
|
||
export async function play_audio(arg: string) { | ||
const encoder = new TextEncoder(); | ||
const view = encoder.encode(arg); | ||
return new Promise((resolve, reject) => { | ||
core.setAsyncHandler(play, (bytes) => { | ||
resolve(textDecoder.decode(bytes)); | ||
}); | ||
core.dispatch(play, view); | ||
}); | ||
} | ||
|
||
await play_audio("music.mp3"); | ||
|