Skip to content

Commit

Permalink
Fix -f
Browse files Browse the repository at this point in the history
  • Loading branch information
synesthesiam committed Jul 10, 2023
1 parent daf6e7f commit 2ab5380
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*
!VERSION
!Makefile
!src/cpp/
!local/en-us/lessac/low/en-us-lessac-low.onnx
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
22 changes: 14 additions & 8 deletions src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<filesystem::path> outputPath;
std::optional<filesystem::path> maybeOutputPath = runConfig.outputPath;

if (runConfig.jsonInput) {
// Each line is a JSON object
Expand All @@ -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<std::string>());
}

Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down

0 comments on commit 2ab5380

Please sign in to comment.