Skip to content

Commit

Permalink
don't stop tts when single sentence encoding fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mkiol committed Sep 25, 2023
1 parent 9820bd7 commit 3040b60
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
25 changes: 21 additions & 4 deletions src/speech_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,8 @@ void speech_service::handle_speech_to_file(const tts_partial_result_t &result) {
}

m_current_task->counter.value += result.text.size();
m_current_task->files.push_back(result.wav_file_path);
if (!result.wav_file_path.isEmpty())
m_current_task->files.push_back(result.wav_file_path);

qDebug() << "partial speech to file progress:"
<< m_current_task->counter.progress();
Expand Down Expand Up @@ -1556,11 +1557,27 @@ void speech_service::handle_tts_queue() {

auto &result = m_tts_queue.front();

m_player.setMedia(QMediaContent{QUrl::fromLocalFile(result.wav_file_path)});
if (!result.wav_file_path.isEmpty()) {
m_player.setMedia(
QMediaContent{QUrl::fromLocalFile(result.wav_file_path)});

m_player.play();
m_player.play();

emit tts_partial_speech_playing(result.text, result.task_id);
emit tts_partial_speech_playing(result.text, result.task_id);
} else if (result.last) {
auto task = result.task_id;

tts_stop_speech(task);
if (m_tts_queue.empty()) {
emit tts_partial_speech_playing("", task);
} else {
m_tts_queue.pop();
}
emit tts_play_speech_finished(task);
} else {
if (!m_tts_queue.empty()) m_tts_queue.pop();
handle_tts_queue();
}
}

void speech_service::handle_tts_engine_error() {
Expand Down
8 changes: 6 additions & 2 deletions src/tts_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,12 @@ void tts_engine::process() {

if (!encode_speech_impl(new_text, output_file)) {
unlink(output_file.c_str());
if (m_call_backs.error) m_call_backs.error();
break;
LOGE("speech encoding error");
if (m_call_backs.speech_encoded) {
m_call_backs.speech_encoded("", "", task.last);
}

continue;
}

if (!model_supports_speed()) apply_speed(output_file);
Expand Down

0 comments on commit 3040b60

Please sign in to comment.