From 2ab5380d1cfb64b228314e37e2ed12807d75f516 Mon Sep 17 00:00:00 2001 From: Michael Hansen Date: Mon, 10 Jul 2023 15:26:52 -0500 Subject: [PATCH] Fix -f --- .dockerignore | 1 + Dockerfile | 2 +- Makefile | 3 ++- src/cpp/main.cpp | 22 ++++++++++++++-------- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.dockerignore b/.dockerignore index b1e1743f..d63fb2a2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,5 @@ * +!VERSION !Makefile !src/cpp/ !local/en-us/lessac/low/en-us-lessac-low.onnx diff --git a/Dockerfile b/Dockerfile index 945a3377..caf5980f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,7 @@ RUN mkdir -p "lib/Linux-$(uname -m)/piper_phonemize" && \ tar -C "lib/Linux-$(uname -m)/piper_phonemize" -xzvf - # Build piper binary -COPY Makefile ./ +COPY VERSION Makefile ./ COPY src/cpp/ ./src/cpp/ RUN make diff --git a/Makefile b/Makefile index 505c9622..ddde320c 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ LIB_DIR := lib/Linux-$(shell uname -m) VERSION := $(cat VERSION) +DOCKER_PLATFORM ?= linux/amd64,linux/arm64,linux/arm/v7 piper: mkdir -p build @@ -12,4 +13,4 @@ clean: rm -rf build/ dist/ docker: - docker buildx build . --platform 'linux/amd64,linux/arm64,linux/arm/v7' --output 'type=local,dest=dist' + docker buildx build . --platform '$(DOCKER_PLATFORM)' --output 'type=local,dest=dist' diff --git a/src/cpp/main.cpp b/src/cpp/main.cpp index fa255a0d..98128056 100644 --- a/src/cpp/main.cpp +++ b/src/cpp/main.cpp @@ -195,7 +195,7 @@ int main(int argc, char *argv[]) { while (getline(cin, line)) { auto outputType = runConfig.outputType; auto speakerId = voice.synthesisConfig.speakerId; - std::optional outputPath; + std::optional maybeOutputPath = runConfig.outputPath; if (runConfig.jsonInput) { // Each line is a JSON object @@ -207,7 +207,7 @@ int main(int argc, char *argv[]) { if (lineRoot.contains("output_file")) { // Override output WAV file path outputType = OUTPUT_FILE; - outputPath = + maybeOutputPath = filesystem::path(lineRoot["output_file"].get()); } @@ -238,14 +238,20 @@ int main(int argc, char *argv[]) { // Generate path using timestamp stringstream outputName; outputName << timestamp << ".wav"; - outputPath = runConfig.outputPath.value(); - outputPath->append(outputName.str()); + filesystem::path outputPath = runConfig.outputPath.value(); + outputPath.append(outputName.str()); // Output audio to automatically-named WAV file in a directory - ofstream audioFile(outputPath->string(), ios::binary); + ofstream audioFile(outputPath.string(), ios::binary); piper::textToWavFile(piperConfig, voice, line, audioFile, result); - cout << outputPath->string() << endl; + cout << outputPath.string() << endl; } else if (outputType == OUTPUT_FILE) { + if (!maybeOutputPath || maybeOutputPath->empty()) { + throw runtime_error("No output path provided"); + } + + filesystem::path outputPath = maybeOutputPath.value(); + if (!runConfig.jsonInput) { // Read all of standard input before synthesizing. // Otherwise, we would overwrite the output file for each line. @@ -259,9 +265,9 @@ int main(int argc, char *argv[]) { } // Output audio to WAV file - ofstream audioFile(outputPath->string(), ios::binary); + ofstream audioFile(outputPath.string(), ios::binary); piper::textToWavFile(piperConfig, voice, line, audioFile, result); - cout << outputPath->string() << endl; + cout << outputPath.string() << endl; } else if (outputType == OUTPUT_STDOUT) { // Output WAV to stdout piper::textToWavFile(piperConfig, voice, line, cout, result);