Rename to piper

This commit is contained in:
Michael Hansen
2023-03-26 21:42:04 -05:00
parent 3dfa161ba5
commit 70afec58bc
62 changed files with 348 additions and 207 deletions
+7 -7
View File
@@ -2,12 +2,12 @@ cmake_minimum_required(VERSION 3.13)
include(CheckIncludeFileCXX)
project(larynx C CXX)
project(piper C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
ADD_EXECUTABLE(larynx main.cpp)
ADD_EXECUTABLE(piper main.cpp)
string(APPEND CMAKE_CXX_FLAGS " -Wall -Wextra -Wl,-rpath,'$ORIGIN'")
string(APPEND CMAKE_C_FLAGS " -Wall -Wextra")
@@ -21,26 +21,26 @@ check_include_file_cxx("pcaudiolib/audio.h" PCAUDIO_INCLUDE_FOUND)
if(PCAUDIO_INCLUDE_FOUND)
option(USE_PCAUDIO "Build with pcaudiolib" ON)
if(USE_PCAUDIO)
target_compile_definitions(larynx PUBLIC HAVE_PCAUDIO)
target_compile_definitions(piper PUBLIC HAVE_PCAUDIO)
set(PCAUDIO_LIBRARIES "pcaudio")
endif()
endif()
set(ONNXRUNTIME_ROOTDIR "/usr/local/include/onnxruntime")
target_link_libraries(larynx
target_link_libraries(piper
onnxruntime
-static-libgcc -static-libstdc++
${ESPEAK_NG_LIBRARIES}
${PCAUDIO_LIBRARIES})
target_link_directories(larynx PUBLIC
target_link_directories(piper PUBLIC
${ESPEAK_NG_LIBRARY_DIRS}
${ONNXRUNTIME_ROOTDIR}/lib)
target_include_directories(larynx PUBLIC
target_include_directories(piper PUBLIC
${ONNXRUNTIME_ROOTDIR}/include
${ESPEAK_NG_INCLUDE_DIRS})
target_compile_options(larynx PUBLIC
target_compile_options(piper PUBLIC
${ESPEAK_NG_CFLAGS_OTHER})
+2 -2
View File
@@ -15,7 +15,7 @@
using namespace std;
using json = nlohmann::json;
namespace larynx {
namespace piper {
typedef char32_t Phoneme;
typedef int64_t PhonemeId;
@@ -145,6 +145,6 @@ void parseModelConfig(json &configRoot, ModelConfig &modelConfig) {
} /* parseModelConfig */
} // namespace larynx
} // namespace piper
#endif // CONFIG_H_
+13 -13
View File
@@ -12,7 +12,7 @@
#include <pcaudiolib/audio.h>
#endif
#include "larynx.hpp"
#include "piper.hpp"
using namespace std;
@@ -23,7 +23,7 @@ struct RunConfig {
filesystem::path modelConfigPath;
OutputType outputType = OUTPUT_PLAY;
optional<filesystem::path> outputPath;
optional<larynx::SpeakerId> speakerId;
optional<piper::SpeakerId> speakerId;
optional<float> noiseScale;
optional<float> lengthScale;
optional<float> noiseW;
@@ -36,9 +36,9 @@ int main(int argc, char *argv[]) {
parseArgs(argc, argv, runConfig);
auto exePath = filesystem::path(argv[0]);
larynx::initialize(exePath.parent_path());
piper::initialize(exePath.parent_path());
larynx::Voice voice;
piper::Voice voice;
auto startTime = chrono::steady_clock::now();
loadVoice(runConfig.modelPath.string(), runConfig.modelConfigPath.string(),
voice, runConfig.speakerId);
@@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
if (runConfig.outputType == OUTPUT_PLAY) {
// Output audio to the default audio device
my_audio = create_audio_device_object(NULL, "larynx", "Text-to-Speech");
my_audio = create_audio_device_object(NULL, "piper", "Text-to-Speech");
// TODO: Support 32-bit sample widths
auto audioFormat = AUDIO_OBJECT_FORMAT_S16LE;
@@ -78,7 +78,7 @@ int main(int argc, char *argv[]) {
#else
if (runConfig.outputType == OUTPUT_PLAY) {
// Cannot play audio directly
cerr << "WARNING: Larynx was not compiled with pcaudiolib. Output audio "
cerr << "WARNING: Piper was not compiled with pcaudiolib. Output audio "
"will be written to the current directory."
<< endl;
runConfig.outputType = OUTPUT_DIRECTORY;
@@ -92,7 +92,7 @@ int main(int argc, char *argv[]) {
}
string line;
larynx::SynthesisResult result;
piper::SynthesisResult result;
while (getline(cin, line)) {
// Path to output WAV file
@@ -108,19 +108,19 @@ int main(int argc, char *argv[]) {
// Output audio to automatically-named WAV file in a directory
ofstream audioFile(outputPath.string(), ios::binary);
larynx::textToWavFile(voice, line, audioFile, result);
piper::textToWavFile(voice, line, audioFile, result);
cout << outputPath.string() << endl;
} else if (runConfig.outputType == OUTPUT_FILE) {
// Output audio to WAV file
ofstream audioFile(runConfig.outputPath.value().string(), ios::binary);
larynx::textToWavFile(voice, line, audioFile, result);
piper::textToWavFile(voice, line, audioFile, result);
} else if (runConfig.outputType == OUTPUT_STDOUT) {
// Output WAV to stdout
larynx::textToWavFile(voice, line, cout, result);
piper::textToWavFile(voice, line, cout, result);
} else if (runConfig.outputType == OUTPUT_PLAY) {
#ifdef HAVE_PCAUDIO
vector<int16_t> audioBuffer;
larynx::textToAudio(voice, line, audioBuffer, result);
piper::textToAudio(voice, line, audioBuffer, result);
int error = audio_object_write(my_audio, (const char *)audioBuffer.data(),
sizeof(int16_t) * audioBuffer.size());
@@ -138,7 +138,7 @@ int main(int argc, char *argv[]) {
<< " sec, audio=" << result.audioSeconds << " sec)" << endl;
}
larynx::terminate();
piper::terminate();
#ifdef HAVE_PCAUDIO
audio_object_close(my_audio);
@@ -211,7 +211,7 @@ void parseArgs(int argc, char *argv[], RunConfig &runConfig) {
runConfig.outputPath = filesystem::path(argv[++i]);
} else if (arg == "-s" || arg == "--speaker") {
ensureArg(argc, argv, i);
runConfig.speakerId = (larynx::SpeakerId)stol(argv[++i]);
runConfig.speakerId = (piper::SpeakerId)stol(argv[++i]);
} else if (arg == "--noise-scale") {
ensureArg(argc, argv, i);
runConfig.noiseScale = stof(argv[++i]);
+3 -3
View File
@@ -7,8 +7,8 @@
using namespace std;
namespace larynx {
const string instanceName{"larynx"};
namespace piper {
const string instanceName{"piper"};
struct ModelSession {
Ort::Session onnx;
@@ -48,6 +48,6 @@ void loadModel(string modelPath, ModelSession &session) {
auto loadDuration = chrono::duration<double>(endTime - startTime);
}
} // namespace larynx
} // namespace piper
#endif // MODEL_H_
+2 -2
View File
@@ -16,7 +16,7 @@
using namespace std;
namespace larynx {
namespace piper {
// Text to phonemes using eSpeak-ng
void phonemize(PhonemizeConfig &phonemizeConfig) {
@@ -103,6 +103,6 @@ void phonemes2ids(PhonemizeConfig &phonemizeConfig,
} /* phonemes2ids */
} // namespace larynx
} // namespace piper
#endif // PHONEMIZE_H_
+5 -5
View File
@@ -1,5 +1,5 @@
#ifndef LARYNX_H_
#define LARYNX_H_
#ifndef PIPER_H_
#define PIPER_H_
#include <filesystem>
#include <iostream>
@@ -17,7 +17,7 @@
using json = nlohmann::json;
namespace larynx {
namespace piper {
struct Voice {
json configRoot;
@@ -106,6 +106,6 @@ void textToWavFile(Voice &voice, string text, ostream &audioFile,
} /* textToWavFile */
} // namespace larynx
} // namespace piper
#endif // LARYNX_H_
#endif // PIPER_H_
+2 -2
View File
@@ -14,7 +14,7 @@
using namespace std;
namespace larynx {
namespace piper {
// Maximum value for 16-bit signed WAV sample
const float MAX_WAV_VALUE = 32767.0f;
@@ -126,6 +126,6 @@ void synthesize(SynthesisConfig &synthesisConfig, ModelSession &session,
Ort::OrtRelease(inputTensors[i].release());
}
}
} // namespace larynx
} // namespace piper
#endif // SYNTHESIZE_H_
+2 -2
View File
@@ -3,7 +3,7 @@
#include <iostream>
namespace larynx {
namespace piper {
struct WavHeader {
uint8_t RIFF[4] = {'R', 'I', 'F', 'F'};
@@ -39,6 +39,6 @@ void writeWavHeader(int sampleRate, int sampleWidth, int channels,
} /* writeWavHeader */
} // namespace larynx
} // namespace piper
#endif // WAVFILE_H_