diff --git a/deps.ts b/deps.ts index 6d6fa93..2274024 100644 --- a/deps.ts +++ b/deps.ts @@ -4,8 +4,6 @@ export { serve } from "https://deno.land/std@0.190.0/http/server.ts"; export { parse } from "https://deno.land/std@0.190.0/flags/mod.ts"; export { dirname } from "https://deno.land/std@0.190.0/path/mod.ts"; export { default as ky } from "https://esm.sh/ky@0.33.2"; -// @deno-types="npm:@types/wav" -export * as wav from "npm:wav"; export { fromUint8Array as toBase64 } from "https://deno.land/x/base64@v0.2.1/mod.ts"; import osPaths from "https://deno.land/x/os_paths@v7.4.0/src/mod.deno.ts"; diff --git a/providers/synthesis.ts b/providers/synthesis.ts index 63ea182..8c9a71c 100644 --- a/providers/synthesis.ts +++ b/providers/synthesis.ts @@ -1,4 +1,3 @@ -import { wav } from "../deps.ts"; import { Provider } from "./index.ts"; import { Readable } from "node:stream"; import { Buffer } from "node:buffer"; @@ -187,42 +186,18 @@ const synthesisProvider: Provider = ({ baseClient, app }) => { intonationScale: audioQuery.intonationScale, prePhonemeLength: audioQuery.prePhonemeLength, postPhonemeLength: audioQuery.postPhonemeLength, - outputSamplingRate: audioQuery.outputSamplingRate * 2, + outputSamplingRate: audioQuery.outputSamplingRate, }; const result = await baseClient.post("v1/synthesis", { json: body, }); - if (!result.body) { + if (!result.ok) { c.status(500); return c.json({ error: "synthesis failed", }); } - const parser = new wav.Reader(); - const writer = new wav.Writer({ - sampleRate: audioQuery.outputStereo - ? audioQuery.outputSamplingRate - : audioQuery.outputSamplingRate * 2, - channels: audioQuery.outputStereo ? 2 : 1, - bitDepth: 16, - }); - // @ts-expect-error Somehow the types are wrong - Readable.fromWeb(result.body).pipe(parser); - parser.on("error", (err) => { - console.error(err); - }); - parser.pipe(writer); - const resampled = await new Promise((resolve) => { - const chunks: Buffer[] = []; - writer.on("data", (chunk) => { - chunks.push(chunk); - }); - writer.on("end", () => { - resolve(Buffer.concat(chunks)); - }); - }); - - return c.body(new Uint8Array(resampled)); + return c.body(result.body); }); };