From d8f2c076ab00798d0596e84f34a8b3b9dfb64499 Mon Sep 17 00:00:00 2001 From: sevenc-nanashi Date: Tue, 27 Jun 2023 06:32:24 +0900 Subject: [PATCH] =?UTF-8?q?Delete:=20outputSamplingRate=E3=81=AE=E3=83=AF?= =?UTF-8?q?=E3=83=BC=E3=82=AF=E3=82=A2=E3=83=A9=E3=82=A6=E3=83=B3=E3=83=89?= =?UTF-8?q?=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deps.ts | 2 -- providers/synthesis.ts | 31 +++---------------------------- 2 files changed, 3 insertions(+), 30 deletions(-) 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); }); };