Skip to content

Commit 3040b60

Browse files
committed
don't stop tts when single sentence encoding fails
1 parent 9820bd7 commit 3040b60

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/speech_service.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,8 @@ void speech_service::handle_speech_to_file(const tts_partial_result_t &result) {
14831483
}
14841484

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

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

15571558
auto &result = m_tts_queue.front();
15581559

1559-
m_player.setMedia(QMediaContent{QUrl::fromLocalFile(result.wav_file_path)});
1560+
if (!result.wav_file_path.isEmpty()) {
1561+
m_player.setMedia(
1562+
QMediaContent{QUrl::fromLocalFile(result.wav_file_path)});
15601563

1561-
m_player.play();
1564+
m_player.play();
15621565

1563-
emit tts_partial_speech_playing(result.text, result.task_id);
1566+
emit tts_partial_speech_playing(result.text, result.task_id);
1567+
} else if (result.last) {
1568+
auto task = result.task_id;
1569+
1570+
tts_stop_speech(task);
1571+
if (m_tts_queue.empty()) {
1572+
emit tts_partial_speech_playing("", task);
1573+
} else {
1574+
m_tts_queue.pop();
1575+
}
1576+
emit tts_play_speech_finished(task);
1577+
} else {
1578+
if (!m_tts_queue.empty()) m_tts_queue.pop();
1579+
handle_tts_queue();
1580+
}
15641581
}
15651582

15661583
void speech_service::handle_tts_engine_error() {

src/tts_engine.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,12 @@ void tts_engine::process() {
454454

455455
if (!encode_speech_impl(new_text, output_file)) {
456456
unlink(output_file.c_str());
457-
if (m_call_backs.error) m_call_backs.error();
458-
break;
457+
LOGE("speech encoding error");
458+
if (m_call_backs.speech_encoded) {
459+
m_call_backs.speech_encoded("", "", task.last);
460+
}
461+
462+
continue;
459463
}
460464

461465
if (!model_supports_speed()) apply_speed(output_file);

0 commit comments

Comments
 (0)