Skip to content

Commit e9e8d68

Browse files
committed
(fix): yarn install works
1 parent 351e1e7 commit e9e8d68

File tree

8 files changed

+40
-27
lines changed

8 files changed

+40
-27
lines changed

.fernignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
README.md
44
CITATIONS.md
55
LICENSE
6+
src/core/fetcher/Fetcher.ts
67
src/wrapper/
78
src/index.ts
89
tests/empathicVoice

src/core/fetcher/Fetcher.ts

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ async function fetcherImpl<R = unknown>(args: Fetcher.Args): Promise<APIResponse
7272
body = args.body;
7373
} else if (args.body instanceof Uint8Array) {
7474
body = args.body;
75+
} else if (args.contentType === "application/x-www-form-urlencoded" && typeof args.body === "string") {
76+
body = args.body;
7577
} else {
7678
body = JSON.stringify(args.body);
7779
}

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * as Hume from "./api";
2-
export { HumeClient } from "./wrapper/HumeClient";
2+
export * from "./wrapper";
33
export { HumeEnvironment } from "./environments";
44
export { HumeError, HumeTimeoutError } from "./errors";

src/wrapper/base64Decode.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function base64Decode(str: string): string | Buffer {
2+
if (typeof Buffer === "function") {
3+
// Node.js environment
4+
return Buffer.from(str, "base64");
5+
} else if (typeof atob === "function") {
6+
// Browser environment
7+
return atob(str);
8+
} else {
9+
throw new Error("Base64 encoding not supported in this environment.");
10+
}
11+
}

src/wrapper/ffmpeg.ts

-16
This file was deleted.

src/wrapper/ffplay.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import commandExists from "command-exists";
2+
import * as errors from "../errors";
3+
import execa from "execa";
4+
5+
export async function ffplay(audio: Buffer): Promise<void> {
6+
if (!commandExists("ffplay")) {
7+
throw new errors.HumeError({
8+
message: `ffplay from ffmpeg not found, necessary to play audio.
9+
On mac you can install it with 'brew install ffmpeg'.
10+
On linux and windows you can install it from https://ffmpeg.org/`,
11+
});
12+
}
13+
const ffmpeg = execa("ffplay", ["-autoexit", "-acodec", "pcm_s16le", "-", "-nodisp"]);
14+
ffmpeg.stdin?.write(audio);
15+
ffmpeg.stdin?.end();
16+
await ffmpeg;
17+
}

src/wrapper/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { ffplay } from "./ffplay";
2+
export { base64Decode } from "./base64Decode";
3+
export { base64Encode } from "./base64Encode";
4+
export { HumeClient } from "./HumeClient";

tests/empathicVoice/chat.test.ts

+4-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { HumeClient } from "../../src/"
2-
import { play } from "../../src/wrapper/empathicVoice/chat/audio/play"
1+
import { HumeClient, ffplay, base64Decode } from "../../src/";
32

43
describe("Empathic Voice Interface", () => {
5-
it("Chat", async () => {
4+
it.skip("Chat", async () => {
65
const hume = new HumeClient({
76
apiKey: "<>",
87
clientSecret: "<>",
@@ -11,8 +10,8 @@ describe("Empathic Voice Interface", () => {
1110
const socket = await hume.empathicVoice.chat.connect({
1211
async onMessage(message): Promise<void> {
1312
if (message.type === "audio_output") {
14-
const decodedString = Buffer.from(message.data, 'base64');
15-
await play(decodedString)
13+
const decoded = Buffer.from(message.data, "base64");
14+
await ffplay(decoded);
1615
}
1716
}
1817
});
@@ -22,10 +21,5 @@ describe("Empathic Voice Interface", () => {
2221
text: "Hello, how are you?",
2322
});
2423

25-
await socket.sendRaw({
26-
type: "user_input",
27-
text: "Nothing much! what about you?",
28-
});
29-
3024
}, 100000);
3125
});

0 commit comments

Comments
 (0)