mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
refactor(tts-local-cli): flatten audio conversion
Amp-Thread-ID: https://ampcode.com/threads/T-019ff438-3b93-77b8-9828-1d3c586cb127
This commit is contained in:
@@ -345,36 +345,16 @@ export function buildCliSpeechProvider(): SpeechProviderPlugin {
|
||||
|
||||
log.debug(`synthesize: format=${result.actualFormat}, size=${result.buffer.length}`);
|
||||
|
||||
let buffer: Buffer;
|
||||
let format: OutputFormat;
|
||||
|
||||
if (req.target === "voice-note") {
|
||||
if (result.actualFormat !== "opus") {
|
||||
const inputFile =
|
||||
result.audioPath ?? path.join(tempDir, `input${getFileExt(result.actualFormat)}`);
|
||||
if (!result.audioPath) {
|
||||
await temp.write(`input${getFileExt(result.actualFormat)}`, result.buffer);
|
||||
}
|
||||
buffer = await convertAudio(inputFile, tempDir, "opus");
|
||||
format = "opus";
|
||||
} else {
|
||||
buffer = result.buffer;
|
||||
format = "opus";
|
||||
}
|
||||
} else {
|
||||
const desired = config.outputFormat ?? "mp3";
|
||||
if (result.actualFormat !== desired) {
|
||||
const inputFile =
|
||||
result.audioPath ?? path.join(tempDir, `input${getFileExt(result.actualFormat)}`);
|
||||
if (!result.audioPath) {
|
||||
await temp.write(`input${getFileExt(result.actualFormat)}`, result.buffer);
|
||||
}
|
||||
buffer = await convertAudio(inputFile, tempDir, desired);
|
||||
format = desired;
|
||||
} else {
|
||||
buffer = result.buffer;
|
||||
format = result.actualFormat;
|
||||
const format: OutputFormat =
|
||||
req.target === "voice-note" ? "opus" : (config.outputFormat ?? "mp3");
|
||||
let buffer = result.buffer;
|
||||
if (result.actualFormat !== format) {
|
||||
const inputName = `input${getFileExt(result.actualFormat)}`;
|
||||
const inputFile = result.audioPath ?? path.join(tempDir, inputName);
|
||||
if (!result.audioPath) {
|
||||
await temp.write(inputName, result.buffer);
|
||||
}
|
||||
buffer = await convertAudio(inputFile, tempDir, format);
|
||||
}
|
||||
|
||||
const fileExtension = format === "opus" ? ".ogg" : `.${format}`;
|
||||
|
||||
Reference in New Issue
Block a user