Unified acronym capitalization
See http://stackoverflow.com/a/27172000/52041
This commit is contained in:
parent
3b599cc751
commit
8e1d1fbdd3
|
@ -111,7 +111,7 @@ set_target_properties(gtest_main PROPERTIES FOLDER lib)
|
||||||
include_directories(SYSTEM "lib/gsl/include")
|
include_directories(SYSTEM "lib/gsl/include")
|
||||||
|
|
||||||
# ... WebRTC
|
# ... WebRTC
|
||||||
set(webRTCFiles
|
set(webRtcFiles
|
||||||
lib/webrtc-8d2248ff/webrtc/common_audio/signal_processing/cross_correlation.c
|
lib/webrtc-8d2248ff/webrtc/common_audio/signal_processing/cross_correlation.c
|
||||||
lib/webrtc-8d2248ff/webrtc/common_audio/signal_processing/division_operations.c
|
lib/webrtc-8d2248ff/webrtc/common_audio/signal_processing/division_operations.c
|
||||||
lib/webrtc-8d2248ff/webrtc/common_audio/signal_processing/downsample_fast.c
|
lib/webrtc-8d2248ff/webrtc/common_audio/signal_processing/downsample_fast.c
|
||||||
|
@ -130,16 +130,16 @@ set(webRTCFiles
|
||||||
lib/webrtc-8d2248ff/webrtc/common_audio/vad/vad_sp.c
|
lib/webrtc-8d2248ff/webrtc/common_audio/vad/vad_sp.c
|
||||||
lib/webrtc-8d2248ff/webrtc/common_audio/vad/webrtc_vad.c
|
lib/webrtc-8d2248ff/webrtc/common_audio/vad/webrtc_vad.c
|
||||||
)
|
)
|
||||||
add_library(webRTC ${webRTCFiles})
|
add_library(webRtc ${webRtcFiles})
|
||||||
target_include_directories(webRTC SYSTEM PUBLIC "lib/webrtc-8d2248ff")
|
target_include_directories(webRtc SYSTEM PUBLIC "lib/webrtc-8d2248ff")
|
||||||
target_compile_options(webRTC PRIVATE ${disableWarningsFlags})
|
target_compile_options(webRtc PRIVATE ${disableWarningsFlags})
|
||||||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||||
target_compile_options(webRTC PRIVATE -pthread -lpthread)
|
target_compile_options(webRtc PRIVATE -pthread -lpthread)
|
||||||
endif()
|
endif()
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
target_compile_definitions(webRTC PRIVATE WEBRTC_POSIX)
|
target_compile_definitions(webRtc PRIVATE WEBRTC_POSIX)
|
||||||
endif()
|
endif()
|
||||||
set_target_properties(webRTC PROPERTIES FOLDER lib)
|
set_target_properties(webRtc PROPERTIES FOLDER lib)
|
||||||
|
|
||||||
# ... whereami
|
# ... whereami
|
||||||
add_library(whereami lib/whereami/src/whereami.c)
|
add_library(whereami lib/whereami/src/whereami.c)
|
||||||
|
@ -236,8 +236,8 @@ add_library(rhubarb-audio
|
||||||
src/audio/AudioClip.h
|
src/audio/AudioClip.h
|
||||||
src/audio/AudioSegment.cpp
|
src/audio/AudioSegment.cpp
|
||||||
src/audio/AudioSegment.h
|
src/audio/AudioSegment.h
|
||||||
src/audio/DCOffset.cpp
|
src/audio/DcOffset.cpp
|
||||||
src/audio/DCOffset.h
|
src/audio/DcOffset.h
|
||||||
src/audio/ioTools.h
|
src/audio/ioTools.h
|
||||||
src/audio/processing.cpp
|
src/audio/processing.cpp
|
||||||
src/audio/processing.h
|
src/audio/processing.h
|
||||||
|
@ -252,7 +252,7 @@ add_library(rhubarb-audio
|
||||||
)
|
)
|
||||||
target_include_directories(rhubarb-audio PUBLIC "src/audio")
|
target_include_directories(rhubarb-audio PUBLIC "src/audio")
|
||||||
target_link_libraries(rhubarb-audio
|
target_link_libraries(rhubarb-audio
|
||||||
webRTC
|
webRtc
|
||||||
rhubarb-logging
|
rhubarb-logging
|
||||||
rhubarb-time
|
rhubarb-time
|
||||||
rhubarb-tools
|
rhubarb-tools
|
||||||
|
|
|
@ -13,9 +13,9 @@ string ExportFormatConverter::getTypeName() {
|
||||||
|
|
||||||
EnumConverter<ExportFormat>::member_data ExportFormatConverter::getMemberData() {
|
EnumConverter<ExportFormat>::member_data ExportFormatConverter::getMemberData() {
|
||||||
return member_data{
|
return member_data{
|
||||||
{ ExportFormat::TSV, "TSV" },
|
{ ExportFormat::Tsv, "tsv" },
|
||||||
{ ExportFormat::XML, "XML" },
|
{ ExportFormat::Xml, "xml" },
|
||||||
{ ExportFormat::JSON, "JSON" }
|
{ ExportFormat::Json, "json" }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,9 @@
|
||||||
#include "EnumConverter.h"
|
#include "EnumConverter.h"
|
||||||
|
|
||||||
enum class ExportFormat {
|
enum class ExportFormat {
|
||||||
TSV,
|
Tsv,
|
||||||
XML,
|
Xml,
|
||||||
JSON
|
Json
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExportFormatConverter : public EnumConverter<ExportFormat> {
|
class ExportFormatConverter : public EnumConverter<ExportFormat> {
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
#include "DCOffset.h"
|
#include "DcOffset.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
using std::unique_ptr;
|
using std::unique_ptr;
|
||||||
using std::make_unique;
|
using std::make_unique;
|
||||||
|
|
||||||
DCOffset::DCOffset(unique_ptr<AudioClip> inputClip, float offset) :
|
DcOffset::DcOffset(unique_ptr<AudioClip> inputClip, float offset) :
|
||||||
inputClip(std::move(inputClip)),
|
inputClip(std::move(inputClip)),
|
||||||
offset(offset),
|
offset(offset),
|
||||||
factor(1 / (1 + std::abs(offset)))
|
factor(1 / (1 + std::abs(offset)))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
unique_ptr<AudioClip> DCOffset::clone() const {
|
unique_ptr<AudioClip> DcOffset::clone() const {
|
||||||
return make_unique<DCOffset>(*this);
|
return make_unique<DcOffset>(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SampleReader DCOffset::createUnsafeSampleReader() const {
|
SampleReader DcOffset::createUnsafeSampleReader() const {
|
||||||
return [read = inputClip->createSampleReader(), factor = factor, offset = offset](size_type index) {
|
return [read = inputClip->createSampleReader(), factor = factor, offset = offset](size_type index) {
|
||||||
float sample = read(index);
|
float sample = read(index);
|
||||||
return sample * factor + offset;
|
return sample * factor + offset;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
float getDCOffset(const AudioClip& audioClip) {
|
float getDcOffset(const AudioClip& audioClip) {
|
||||||
int flatMeanSampleCount, fadingMeanSampleCount;
|
int flatMeanSampleCount, fadingMeanSampleCount;
|
||||||
int sampleRate = audioClip.getSampleRate();
|
int sampleRate = audioClip.getSampleRate();
|
||||||
if (audioClip.size() > 4 * sampleRate) {
|
if (audioClip.size() > 4 * sampleRate) {
|
||||||
|
@ -49,16 +49,16 @@ float getDCOffset(const AudioClip& audioClip) {
|
||||||
return static_cast<float>(offset);
|
return static_cast<float>(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioEffect addDCOffset(float offset, float epsilon) {
|
AudioEffect addDcOffset(float offset, float epsilon) {
|
||||||
return [offset, epsilon](unique_ptr<AudioClip> inputClip) -> unique_ptr<AudioClip> {
|
return [offset, epsilon](unique_ptr<AudioClip> inputClip) -> unique_ptr<AudioClip> {
|
||||||
if (std::abs(offset) < epsilon) return std::move(inputClip);
|
if (std::abs(offset) < epsilon) return std::move(inputClip);
|
||||||
return make_unique<DCOffset>(std::move(inputClip), offset);
|
return make_unique<DcOffset>(std::move(inputClip), offset);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioEffect removeDCOffset(float epsilon) {
|
AudioEffect removeDcOffset(float epsilon) {
|
||||||
return [epsilon](unique_ptr<AudioClip> inputClip) {
|
return [epsilon](unique_ptr<AudioClip> inputClip) {
|
||||||
float offset = getDCOffset(*inputClip);
|
float offset = getDcOffset(*inputClip);
|
||||||
return std::move(inputClip) | addDCOffset(-offset, epsilon);
|
return std::move(inputClip) | addDcOffset(-offset, epsilon);
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -4,9 +4,9 @@
|
||||||
|
|
||||||
// Applies a constant DC offset to an audio clip and reduces its amplitude
|
// Applies a constant DC offset to an audio clip and reduces its amplitude
|
||||||
// to prevent clipping
|
// to prevent clipping
|
||||||
class DCOffset : public AudioClip {
|
class DcOffset : public AudioClip {
|
||||||
public:
|
public:
|
||||||
DCOffset(std::unique_ptr<AudioClip> inputClip, float offset);
|
DcOffset(std::unique_ptr<AudioClip> inputClip, float offset);
|
||||||
std::unique_ptr<AudioClip> clone() const override;
|
std::unique_ptr<AudioClip> clone() const override;
|
||||||
int getSampleRate() const override;
|
int getSampleRate() const override;
|
||||||
size_type size() const override;
|
size_type size() const override;
|
||||||
|
@ -18,15 +18,15 @@ private:
|
||||||
float factor;
|
float factor;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline int DCOffset::getSampleRate() const {
|
inline int DcOffset::getSampleRate() const {
|
||||||
return inputClip->getSampleRate();
|
return inputClip->getSampleRate();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline AudioClip::size_type DCOffset::size() const {
|
inline AudioClip::size_type DcOffset::size() const {
|
||||||
return inputClip->size();
|
return inputClip->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
float getDCOffset(const AudioClip& audioClip);
|
float getDcOffset(const AudioClip& audioClip);
|
||||||
|
|
||||||
AudioEffect addDCOffset(float offset, float epsilon = 1.0f / 15000);
|
AudioEffect addDcOffset(float offset, float epsilon = 1.0f / 15000);
|
||||||
AudioEffect removeDCOffset(float epsilon = 1.0f / 15000);
|
AudioEffect removeDcOffset(float epsilon = 1.0f / 15000);
|
|
@ -26,7 +26,7 @@ int roundToEven(int i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Codec {
|
namespace Codec {
|
||||||
constexpr int PCM = 0x01;
|
constexpr int Pcm = 0x01;
|
||||||
constexpr int Float = 0x03;
|
constexpr int Float = 0x03;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ WaveFileReader::WaveFileReader(path filePath) :
|
||||||
// Determine sample format
|
// Determine sample format
|
||||||
int bytesPerSample;
|
int bytesPerSample;
|
||||||
switch (codec) {
|
switch (codec) {
|
||||||
case Codec::PCM:
|
case Codec::Pcm:
|
||||||
// Determine sample size.
|
// Determine sample size.
|
||||||
// According to the WAVE standard, sample sizes that are not multiples of 8 bits
|
// According to the WAVE standard, sample sizes that are not multiples of 8 bits
|
||||||
// (e.g. 12 bits) can be treated like the next-larger byte size.
|
// (e.g. 12 bits) can be treated like the next-larger byte size.
|
||||||
|
@ -135,7 +135,7 @@ WaveFileReader::WaveFileReader(path filePath) :
|
||||||
default:
|
default:
|
||||||
throw runtime_error(format(
|
throw runtime_error(format(
|
||||||
"Unsupported audio codec: '{}'. Only uncompressed codecs ('{}' and '{}') are supported.",
|
"Unsupported audio codec: '{}'. Only uncompressed codecs ('{}' and '{}') are supported.",
|
||||||
codecToString(codec), codecToString(Codec::PCM), codecToString(Codec::Float)));
|
codecToString(codec), codecToString(Codec::Pcm), codecToString(Codec::Float)));
|
||||||
}
|
}
|
||||||
formatInfo.bytesPerFrame = bytesPerSample * formatInfo.channelCount;
|
formatInfo.bytesPerFrame = bytesPerSample * formatInfo.channelCount;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "voiceActivityDetection.h"
|
#include "voiceActivityDetection.h"
|
||||||
#include "DCOffset.h"
|
#include "DcOffset.h"
|
||||||
#include "SampleRateConverter.h"
|
#include "SampleRateConverter.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "pairs.h"
|
#include "pairs.h"
|
||||||
|
@ -68,7 +68,7 @@ BoundedTimeline<void> webRtcDetectVoiceActivity(const AudioClip& audioClip, Prog
|
||||||
|
|
||||||
BoundedTimeline<void> detectVoiceActivity(const AudioClip& inputAudioClip, int maxThreadCount, ProgressSink& progressSink) {
|
BoundedTimeline<void> detectVoiceActivity(const AudioClip& inputAudioClip, int maxThreadCount, ProgressSink& progressSink) {
|
||||||
// Prepare audio for VAD
|
// Prepare audio for VAD
|
||||||
const unique_ptr<AudioClip> audioClip = inputAudioClip.clone() | resample(16000) | removeDCOffset();
|
const unique_ptr<AudioClip> audioClip = inputAudioClip.clone() | resample(16000) | removeDcOffset();
|
||||||
|
|
||||||
BoundedTimeline<void> activity(audioClip->getTruncatedRange());
|
BoundedTimeline<void> activity(audioClip->getTruncatedRange());
|
||||||
std::mutex activityMutex;
|
std::mutex activityMutex;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
string escapeJSONString(const string& s) {
|
string escapeJsonString(const string& s) {
|
||||||
string result;
|
string result;
|
||||||
for (char c : s) {
|
for (char c : s) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
@ -25,12 +25,12 @@ string escapeJSONString(const string& s) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSONExporter::exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) {
|
void JsonExporter::exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) {
|
||||||
// Export as JSON.
|
// Export as JSON.
|
||||||
// I'm not using a library because the code is short enough without one and it lets me control the formatting.
|
// I'm not using a library because the code is short enough without one and it lets me control the formatting.
|
||||||
outputStream << "{\n";
|
outputStream << "{\n";
|
||||||
outputStream << " \"metadata\": {\n";
|
outputStream << " \"metadata\": {\n";
|
||||||
outputStream << " \"soundFile\": \"" << escapeJSONString(inputFilePath.string()) << "\",\n";
|
outputStream << " \"soundFile\": \"" << escapeJsonString(inputFilePath.string()) << "\",\n";
|
||||||
outputStream << " \"duration\": " << formatDuration(shapes.getRange().getDuration()) << "\n";
|
outputStream << " \"duration\": " << formatDuration(shapes.getRange().getDuration()) << "\n";
|
||||||
outputStream << " },\n";
|
outputStream << " },\n";
|
||||||
outputStream << " \"mouthCues\": [\n";
|
outputStream << " \"mouthCues\": [\n";
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "Exporter.h"
|
#include "Exporter.h"
|
||||||
|
|
||||||
class JSONExporter : public Exporter {
|
class JsonExporter : public Exporter {
|
||||||
public:
|
public:
|
||||||
void exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) override;
|
void exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "TsvExporter.h"
|
#include "TsvExporter.h"
|
||||||
|
|
||||||
void TSVExporter::exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) {
|
void TsvExporter::exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) {
|
||||||
UNUSED(inputFilePath);
|
UNUSED(inputFilePath);
|
||||||
|
|
||||||
// Output shapes with start times
|
// Output shapes with start times
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "Exporter.h"
|
#include "Exporter.h"
|
||||||
|
|
||||||
class TSVExporter : public Exporter {
|
class TsvExporter : public Exporter {
|
||||||
public:
|
public:
|
||||||
void exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) override;
|
void exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) override;
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
using std::string;
|
using std::string;
|
||||||
using boost::property_tree::ptree;
|
using boost::property_tree::ptree;
|
||||||
|
|
||||||
void XMLExporter::exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) {
|
void XmlExporter::exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) {
|
||||||
ptree tree;
|
ptree tree;
|
||||||
|
|
||||||
// Add metadata
|
// Add metadata
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include "Exporter.h"
|
#include "Exporter.h"
|
||||||
|
|
||||||
class XMLExporter : public Exporter {
|
class XmlExporter : public Exporter {
|
||||||
public:
|
public:
|
||||||
void exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) override;
|
void exportShapes(const boost::filesystem::path& inputFilePath, const ContinuousTimeline<Shape>& shapes, std::ostream& outputStream) override;
|
||||||
};
|
};
|
||||||
|
|
16
src/main.cpp
16
src/main.cpp
|
@ -68,12 +68,12 @@ void addFileSink(path path, logging::Level minLevel) {
|
||||||
|
|
||||||
unique_ptr<Exporter> createExporter(ExportFormat exportFormat) {
|
unique_ptr<Exporter> createExporter(ExportFormat exportFormat) {
|
||||||
switch (exportFormat) {
|
switch (exportFormat) {
|
||||||
case ExportFormat::TSV:
|
case ExportFormat::Tsv:
|
||||||
return make_unique<TSVExporter>();
|
return make_unique<TsvExporter>();
|
||||||
case ExportFormat::XML:
|
case ExportFormat::Xml:
|
||||||
return make_unique<XMLExporter>();
|
return make_unique<XmlExporter>();
|
||||||
case ExportFormat::JSON:
|
case ExportFormat::Json:
|
||||||
return make_unique<JSONExporter>();
|
return make_unique<JsonExporter>();
|
||||||
default:
|
default:
|
||||||
throw std::runtime_error("Unknown export format.");
|
throw std::runtime_error("Unknown export format.");
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ int main(int argc, char *argv[]) {
|
||||||
tclap::ValueArg<string> dialogFile("d", "dialogFile", "A file containing the text of the dialog.", false, string(), "string", cmd);
|
tclap::ValueArg<string> dialogFile("d", "dialogFile", "A file containing the text of the dialog.", false, string(), "string", cmd);
|
||||||
auto exportFormats = vector<ExportFormat>(ExportFormatConverter::get().getValues());
|
auto exportFormats = vector<ExportFormat>(ExportFormatConverter::get().getValues());
|
||||||
tclap::ValuesConstraint<ExportFormat> exportFormatConstraint(exportFormats);
|
tclap::ValuesConstraint<ExportFormat> exportFormatConstraint(exportFormats);
|
||||||
tclap::ValueArg<ExportFormat> exportFormat("f", "exportFormat", "The export format.", false, ExportFormat::TSV, &exportFormatConstraint, cmd);
|
tclap::ValueArg<ExportFormat> exportFormat("f", "exportFormat", "The export format.", false, ExportFormat::Tsv, &exportFormatConstraint, cmd);
|
||||||
tclap::UnlabeledValueArg<string> inputFileName("inputFile", "The input file. Must be a sound file in WAVE format.", true, "", "string", cmd);
|
tclap::UnlabeledValueArg<string> inputFileName("inputFile", "The input file. Must be a sound file in WAVE format.", true, "", "string", cmd);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -132,7 +132,7 @@ int main(int argc, char *argv[]) {
|
||||||
// Animate the recording
|
// Animate the recording
|
||||||
animation = animateWaveFile(
|
animation = animateWaveFile(
|
||||||
inputFileName.getValue(),
|
inputFileName.getValue(),
|
||||||
dialogFile.isSet() ? readUTF8File(path(dialogFile.getValue())) : boost::optional<u32string>(),
|
dialogFile.isSet() ? readUtf8File(path(dialogFile.getValue())) : boost::optional<u32string>(),
|
||||||
maxThreadCount.getValue(),
|
maxThreadCount.getValue(),
|
||||||
progressBar);
|
progressBar);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <gsl_util.h>
|
#include <gsl_util.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include "DCOffset.h"
|
#include "DcOffset.h"
|
||||||
#include "Timeline.h"
|
#include "Timeline.h"
|
||||||
#include "voiceActivityDetection.h"
|
#include "voiceActivityDetection.h"
|
||||||
#include "AudioSegment.h"
|
#include "AudioSegment.h"
|
||||||
|
@ -427,7 +427,7 @@ BoundedTimeline<Phone> recognizePhones(
|
||||||
ProgressSink& dialogProgressSink = totalProgressMerger.addSink(15);
|
ProgressSink& dialogProgressSink = totalProgressMerger.addSink(15);
|
||||||
|
|
||||||
// Make sure audio stream has no DC offset
|
// Make sure audio stream has no DC offset
|
||||||
const unique_ptr<AudioClip> audioClip = inputAudioClip.clone() | removeDCOffset();
|
const unique_ptr<AudioClip> audioClip = inputAudioClip.clone() | removeDcOffset();
|
||||||
|
|
||||||
// Split audio into utterances
|
// Split audio into utterances
|
||||||
BoundedTimeline<void> utterances;
|
BoundedTimeline<void> utterances;
|
||||||
|
|
|
@ -74,7 +74,7 @@ optional<string> findSimilarDictionaryWord(const string& word, function<bool(con
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> tokenizeText(const u32string& text, function<bool(const string&)> dictionaryContains) {
|
vector<string> tokenizeText(const u32string& text, function<bool(const string&)> dictionaryContains) {
|
||||||
vector<string> words = tokenizeViaFlite(toASCII(text));
|
vector<string> words = tokenizeViaFlite(toAscii(text));
|
||||||
|
|
||||||
// Join words separated by apostophes
|
// Join words separated by apostophes
|
||||||
for (int i = words.size() - 1; i > 0; --i) {
|
for (int i = words.size() - 1; i > 0; --i) {
|
||||||
|
|
|
@ -91,7 +91,7 @@ wstring latin1ToWide(const string& s) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<char> toASCII(char32_t ch) {
|
optional<char> toAscii(char32_t ch) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
#include "asciiCases.cpp"
|
#include "asciiCases.cpp"
|
||||||
default:
|
default:
|
||||||
|
@ -99,10 +99,10 @@ optional<char> toASCII(char32_t ch) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string toASCII(const u32string& s) {
|
string toAscii(const u32string& s) {
|
||||||
string result;
|
string result;
|
||||||
for (char32_t ch : s) {
|
for (char32_t ch : s) {
|
||||||
optional<char> ascii = toASCII(ch);
|
optional<char> ascii = toAscii(ch);
|
||||||
if (ascii) result.append(1, *ascii);
|
if (ascii) result.append(1, *ascii);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -12,9 +12,9 @@ std::vector<std::string> wrapString(const std::string& s, int lineLength, int ha
|
||||||
|
|
||||||
std::wstring latin1ToWide(const std::string& s);
|
std::wstring latin1ToWide(const std::string& s);
|
||||||
|
|
||||||
boost::optional<char> toASCII(char32_t ch);
|
boost::optional<char> toAscii(char32_t ch);
|
||||||
|
|
||||||
std::string toASCII(const std::u32string& s);
|
std::string toAscii(const std::u32string& s);
|
||||||
|
|
||||||
std::u32string utf8ToUtf32(const std::string& s);
|
std::u32string utf8ToUtf32(const std::string& s);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ using std::string;
|
||||||
using std::u32string;
|
using std::u32string;
|
||||||
using boost::filesystem::path;
|
using boost::filesystem::path;
|
||||||
|
|
||||||
u32string readUTF8File(path filePath) {
|
u32string readUtf8File(path filePath) {
|
||||||
if (!exists(filePath)) {
|
if (!exists(filePath)) {
|
||||||
throw std::invalid_argument(fmt::format("File {} does not exist.", filePath));
|
throw std::invalid_argument(fmt::format("File {} does not exist.", filePath));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
std::u32string readUTF8File(boost::filesystem::path filePath);
|
std::u32string readUtf8File(boost::filesystem::path filePath);
|
|
@ -81,11 +81,11 @@ TEST(latin1ToWide, basic) {
|
||||||
EXPECT_EQ(pangramWide, latin1ToWide(pangramLatin1));
|
EXPECT_EQ(pangramWide, latin1ToWide(pangramLatin1));
|
||||||
}
|
}
|
||||||
|
|
||||||
// toASCII
|
// toAscii
|
||||||
|
|
||||||
TEST(toASCII, string) {
|
TEST(toAscii, string) {
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
"A naive man called was having pina colada and creme brulee.",
|
"A naive man called was having pina colada and creme brulee.",
|
||||||
toASCII(U"A naïve man called 晨 was having piña colada and crème brûlée."));
|
toAscii(U"A naïve man called 晨 was having piña colada and crème brûlée."));
|
||||||
EXPECT_EQ(string(""), toASCII(U""));
|
EXPECT_EQ(string(""), toAscii(U""));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue