Skip to content

Commit

Permalink
chore: Update version to 0.0.4 and add line-by-line reading mode
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil committed Jul 22, 2024
1 parent 61b843f commit 85363d9
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion buildspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"name": "obs-squawk",
"displayName": "OBS Squawk Real-Time Text-to-Speech Plugin",
"version": "0.0.3",
"version": "0.0.4",
"author": "Roy Shilkrot",
"website": "https://github.com/occ-ai/obs-squawk",
"email": "[email protected]",
Expand Down
2 changes: 2 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ Speaker_ID="Speaker ID"
Model="Model"
Delete_Cached_Models="Delete Cached Models"
Speed="Speed"
Line_By_Line="Read Line By Line"
line_by_line_help="If enabled, the input text or file will be read line by line, otherwise, the entire input text or file will be read at once."
22 changes: 17 additions & 5 deletions src/input-thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <iostream>
#include <filesystem>
#include <fstream>
#include <sstream>

#include <obs.h>

Expand All @@ -30,11 +31,12 @@ void InputThread::run()
if (std::filesystem::exists(filePath)) {
std::ifstream fileStream(filePath);
if (fileStream.is_open()) {
std::string line;
while (std::getline(fileStream, line)) {
fileContents += line;
}
std::stringstream buffer;
buffer << fileStream.rdbuf();
fileContents = buffer.str();
fileStream.close();
} else {
obs_log(LOG_ERROR, "Failed to open file: %s", file.c_str());
}
}
if (fileContents != lastFileValue) {
Expand Down Expand Up @@ -70,7 +72,17 @@ void InputThread::run()
std::thread generationThread([this, new_content_for_generation]() {
obs_log(LOG_DEBUG, "Generating speech from input: %s",
new_content_for_generation.c_str());
speechGenerationCallback(new_content_for_generation);
if (this->readingMode == ReadingMode::LineByLine) {
// Split the input into lines and generate speech for each line
std::istringstream iss(new_content_for_generation);
std::string line;
while (std::getline(iss, line)) {
this->speechGenerationCallback(line);
}
return;
} else {
speechGenerationCallback(new_content_for_generation);
}
});
generationThread.detach();
}
Expand Down
5 changes: 5 additions & 0 deletions src/input-thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <string>
#include <functional>

enum class ReadingMode { Whole, LineByLine };

class InputThread {
public:
InputThread();
Expand All @@ -29,6 +31,8 @@ class InputThread {
}

void setFile(const std::string &filePath) { file = filePath; }
void setReadingMode(ReadingMode mode) { readingMode = mode; }
void setInterval(uint32_t milliseconds) { interval = milliseconds; }

void setOBSTextSource(const std::string &sourceName) { obsTextSource = sourceName; }

Expand All @@ -46,6 +50,7 @@ class InputThread {
uint32_t interval = 1000;
std::string lastFileValue;
std::string lastOBSTextSourceValue;
ReadingMode readingMode = ReadingMode::Whole;

void run();
};
Expand Down
12 changes: 11 additions & 1 deletion src/squawk-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ void squawk_source_defaults(obs_data_t *settings)
obs_data_set_default_string(settings, "model", "vits-coqui-en-vctk");
obs_data_set_default_string(settings, "input_source", "none");
obs_data_set_default_string(settings, "file", "");
obs_data_set_default_bool(settings, "line_by_line", false);
obs_data_set_default_bool(settings, "phonetic_transcription", true);
}

bool add_sources_to_list(void *list_property, obs_source_t *source)
{
auto source_id = obs_source_get_id(source);
if (strcmp(source_id, "text_ft2_source_v2") != 0 &&
strcmp(source_id, "text_gdiplus_v2") != 0) {
strcmp(source_id, "text_gdiplus_v2") != 0 &&
strcmp(source_id, "text_gdiplus_v3") != 0) {
return true;
}

Expand Down Expand Up @@ -156,6 +158,11 @@ obs_properties_t *squawk_source_properties(void *data)
obs_enum_sources(add_sources_to_list, input_source);
// add file property
obs_properties_add_path(ppts, "file", MT_("File"), OBS_PATH_FILE, nullptr, nullptr);
// add line-by-line boolean property
obs_properties_add_bool(ppts, "line_by_line", MT_("Line_By_Line"));
// add help text for line-by-line
obs_property_set_long_description(obs_properties_get(ppts, "line_by_line"),
MT_("line_by_line_help"));

// add text property
obs_properties_add_text(ppts, "text", MT_("Text"), OBS_TEXT_DEFAULT);
Expand Down Expand Up @@ -235,6 +242,9 @@ void squawk_source_update(void *data, obs_data_t *settings)
}
squawk_data->inputThread->setOBSTextSource(source);
squawk_data->inputThread->setFile(obs_data_get_string(settings, "file"));
squawk_data->inputThread->setReadingMode(obs_data_get_bool(settings, "line_by_line")
? ReadingMode::LineByLine
: ReadingMode::Whole);

std::string new_model_name = obs_data_get_string(settings, "model");
if (new_model_name != squawk_data->tts_context.model_name) {
Expand Down

0 comments on commit 85363d9

Please sign in to comment.