Skip to content

Commit

Permalink
Delete: outputSamplingRateのワークアラウンドを削除
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenc-nanashi committed Jun 26, 2023
1 parent a8b58a5 commit d8f2c07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 30 deletions.
2 changes: 0 additions & 2 deletions deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ export { serve } from "https://deno.land/[email protected]/http/server.ts";
export { parse } from "https://deno.land/[email protected]/flags/mod.ts";
export { dirname } from "https://deno.land/[email protected]/path/mod.ts";
export { default as ky } from "https://esm.sh/[email protected]";
// @deno-types="npm:@types/wav"
export * as wav from "npm:wav";
export { fromUint8Array as toBase64 } from "https://deno.land/x/[email protected]/mod.ts";
import osPaths from "https://deno.land/x/[email protected]/src/mod.deno.ts";

Expand Down
31 changes: 3 additions & 28 deletions providers/synthesis.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { wav } from "../deps.ts";
import { Provider } from "./index.ts";
import { Readable } from "node:stream";
import { Buffer } from "node:buffer";
Expand Down Expand Up @@ -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<Buffer>((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);
});
};

Expand Down

0 comments on commit d8f2c07

Please sign in to comment.