Cancel speech recognition by timeout.
This commit is contained in:
parent
b56b778660
commit
677c5795a3
@ -3558,6 +3558,8 @@ void Td::clear() {
|
|||||||
LOG(DEBUG) << "TopDialogManager actor was cleared" << timer;
|
LOG(DEBUG) << "TopDialogManager actor was cleared" << timer;
|
||||||
updates_manager_actor_.reset();
|
updates_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "UpdatesManager actor was cleared" << timer;
|
LOG(DEBUG) << "UpdatesManager actor was cleared" << timer;
|
||||||
|
voice_notes_manager_actor_.reset();
|
||||||
|
LOG(DEBUG) << "VoiceNotesManager actor was cleared" << timer;
|
||||||
web_pages_manager_actor_.reset();
|
web_pages_manager_actor_.reset();
|
||||||
LOG(DEBUG) << "WebPagesManager actor was cleared" << timer;
|
LOG(DEBUG) << "WebPagesManager actor was cleared" << timer;
|
||||||
}
|
}
|
||||||
@ -3981,7 +3983,6 @@ void Td::init_managers() {
|
|||||||
documents_manager_ = make_unique<DocumentsManager>(this);
|
documents_manager_ = make_unique<DocumentsManager>(this);
|
||||||
video_notes_manager_ = make_unique<VideoNotesManager>(this);
|
video_notes_manager_ = make_unique<VideoNotesManager>(this);
|
||||||
videos_manager_ = make_unique<VideosManager>(this);
|
videos_manager_ = make_unique<VideosManager>(this);
|
||||||
voice_notes_manager_ = make_unique<VoiceNotesManager>(this);
|
|
||||||
|
|
||||||
animations_manager_ = make_unique<AnimationsManager>(this, create_reference());
|
animations_manager_ = make_unique<AnimationsManager>(this, create_reference());
|
||||||
animations_manager_actor_ = register_actor("AnimationsManager", animations_manager_.get());
|
animations_manager_actor_ = register_actor("AnimationsManager", animations_manager_.get());
|
||||||
@ -4037,6 +4038,8 @@ void Td::init_managers() {
|
|||||||
updates_manager_ = make_unique<UpdatesManager>(this, create_reference());
|
updates_manager_ = make_unique<UpdatesManager>(this, create_reference());
|
||||||
updates_manager_actor_ = register_actor("UpdatesManager", updates_manager_.get());
|
updates_manager_actor_ = register_actor("UpdatesManager", updates_manager_.get());
|
||||||
G()->set_updates_manager(updates_manager_actor_.get());
|
G()->set_updates_manager(updates_manager_actor_.get());
|
||||||
|
voice_notes_manager_ = make_unique<VoiceNotesManager>(this, create_reference());
|
||||||
|
voice_notes_manager_actor_ = register_actor("VoiceNotesManager", voice_notes_manager_.get());
|
||||||
web_pages_manager_ = make_unique<WebPagesManager>(this, create_reference());
|
web_pages_manager_ = make_unique<WebPagesManager>(this, create_reference());
|
||||||
web_pages_manager_actor_ = register_actor("WebPagesManager", web_pages_manager_.get());
|
web_pages_manager_actor_ = register_actor("WebPagesManager", web_pages_manager_.get());
|
||||||
G()->set_web_pages_manager(web_pages_manager_actor_.get());
|
G()->set_web_pages_manager(web_pages_manager_actor_.get());
|
||||||
|
@ -137,7 +137,6 @@ class Td final : public Actor {
|
|||||||
unique_ptr<DocumentsManager> documents_manager_;
|
unique_ptr<DocumentsManager> documents_manager_;
|
||||||
unique_ptr<VideoNotesManager> video_notes_manager_;
|
unique_ptr<VideoNotesManager> video_notes_manager_;
|
||||||
unique_ptr<VideosManager> videos_manager_;
|
unique_ptr<VideosManager> videos_manager_;
|
||||||
unique_ptr<VoiceNotesManager> voice_notes_manager_;
|
|
||||||
|
|
||||||
unique_ptr<AnimationsManager> animations_manager_;
|
unique_ptr<AnimationsManager> animations_manager_;
|
||||||
ActorOwn<AnimationsManager> animations_manager_actor_;
|
ActorOwn<AnimationsManager> animations_manager_actor_;
|
||||||
@ -185,6 +184,8 @@ class Td final : public Actor {
|
|||||||
ActorOwn<TopDialogManager> top_dialog_manager_actor_;
|
ActorOwn<TopDialogManager> top_dialog_manager_actor_;
|
||||||
unique_ptr<UpdatesManager> updates_manager_;
|
unique_ptr<UpdatesManager> updates_manager_;
|
||||||
ActorOwn<UpdatesManager> updates_manager_actor_;
|
ActorOwn<UpdatesManager> updates_manager_actor_;
|
||||||
|
unique_ptr<VoiceNotesManager> voice_notes_manager_;
|
||||||
|
ActorOwn<VoiceNotesManager> voice_notes_manager_actor_;
|
||||||
unique_ptr<WebPagesManager> web_pages_manager_;
|
unique_ptr<WebPagesManager> web_pages_manager_;
|
||||||
ActorOwn<WebPagesManager> web_pages_manager_actor_;
|
ActorOwn<WebPagesManager> web_pages_manager_actor_;
|
||||||
|
|
||||||
|
@ -94,7 +94,25 @@ class RateTranscribedAudioQuery final : public Td::ResultHandler {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
VoiceNotesManager::VoiceNotesManager(Td *td) : td_(td) {
|
VoiceNotesManager::VoiceNotesManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||||
|
voice_note_transcription_timeout_.set_callback(on_voice_note_transcription_timeout_callback);
|
||||||
|
voice_note_transcription_timeout_.set_callback_data(static_cast<void *>(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoiceNotesManager::tear_down() {
|
||||||
|
parent_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void VoiceNotesManager::on_voice_note_transcription_timeout_callback(void *voice_notes_manager_ptr,
|
||||||
|
int64 transcription_id) {
|
||||||
|
if (G()->close_flag()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto voice_notes_manager = static_cast<VoiceNotesManager *>(voice_notes_manager_ptr);
|
||||||
|
send_closure_later(voice_notes_manager->actor_id(voice_notes_manager),
|
||||||
|
&VoiceNotesManager::on_pending_voice_note_transcription_failed, transcription_id,
|
||||||
|
Status::Error(500, "Timeout expired"));
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 VoiceNotesManager::get_voice_note_duration(FileId file_id) const {
|
int32 VoiceNotesManager::get_voice_note_duration(FileId file_id) const {
|
||||||
@ -302,6 +320,7 @@ void VoiceNotesManager::on_voice_note_transcribed(FileId file_id, string &&text,
|
|||||||
}
|
}
|
||||||
bool is_inserted = pending_voice_note_transcription_queries_.emplace(transcription_id, file_id).second;
|
bool is_inserted = pending_voice_note_transcription_queries_.emplace(transcription_id, file_id).second;
|
||||||
CHECK(is_inserted);
|
CHECK(is_inserted);
|
||||||
|
voice_note_transcription_timeout_.set_timeout_in(transcription_id, TRANSCRIPTION_TIMEOUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,6 +354,7 @@ void VoiceNotesManager::on_update_transcribed_audio(string &&text, int64 transcr
|
|||||||
}
|
}
|
||||||
auto file_id = it->second;
|
auto file_id = it->second;
|
||||||
pending_voice_note_transcription_queries_.erase(it);
|
pending_voice_note_transcription_queries_.erase(it);
|
||||||
|
voice_note_transcription_timeout_.cancel_timeout(transcription_id);
|
||||||
|
|
||||||
on_voice_note_transcribed(file_id, std::move(text), transcription_id, is_final);
|
on_voice_note_transcribed(file_id, std::move(text), transcription_id, is_final);
|
||||||
}
|
}
|
||||||
@ -346,6 +366,8 @@ void VoiceNotesManager::on_pending_voice_note_transcription_failed(int64 transcr
|
|||||||
}
|
}
|
||||||
auto file_id = it->second;
|
auto file_id = it->second;
|
||||||
pending_voice_note_transcription_queries_.erase(it);
|
pending_voice_note_transcription_queries_.erase(it);
|
||||||
|
voice_note_transcription_timeout_.cancel_timeout(transcription_id);
|
||||||
|
|
||||||
on_voice_note_transcription_failed(file_id, std::move(error));
|
on_voice_note_transcription_failed(file_id, std::move(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,9 @@
|
|||||||
#include "td/telegram/telegram_api.h"
|
#include "td/telegram/telegram_api.h"
|
||||||
#include "td/telegram/Version.h"
|
#include "td/telegram/Version.h"
|
||||||
|
|
||||||
|
#include "td/actor/actor.h"
|
||||||
#include "td/actor/PromiseFuture.h"
|
#include "td/actor/PromiseFuture.h"
|
||||||
|
#include "td/actor/Timeout.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/FlatHashMap.h"
|
#include "td/utils/FlatHashMap.h"
|
||||||
@ -24,9 +26,9 @@ namespace td {
|
|||||||
|
|
||||||
class Td;
|
class Td;
|
||||||
|
|
||||||
class VoiceNotesManager {
|
class VoiceNotesManager final : public Actor {
|
||||||
public:
|
public:
|
||||||
explicit VoiceNotesManager(Td *td);
|
VoiceNotesManager(Td *td, ActorShared<> parent);
|
||||||
|
|
||||||
int32 get_voice_note_duration(FileId file_id) const;
|
int32 get_voice_note_duration(FileId file_id) const;
|
||||||
|
|
||||||
@ -66,6 +68,8 @@ class VoiceNotesManager {
|
|||||||
FileId parse_voice_note(ParserT &parser);
|
FileId parse_voice_note(ParserT &parser);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static constexpr int32 TRANSCRIPTION_TIMEOUT = 60;
|
||||||
|
|
||||||
class VoiceNote {
|
class VoiceNote {
|
||||||
public:
|
public:
|
||||||
string mime_type;
|
string mime_type;
|
||||||
@ -78,6 +82,8 @@ class VoiceNotesManager {
|
|||||||
FileId file_id;
|
FileId file_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void on_voice_note_transcription_timeout_callback(void *voice_notes_manager_ptr, int64 transcription_id);
|
||||||
|
|
||||||
VoiceNote *get_voice_note(FileId file_id);
|
VoiceNote *get_voice_note(FileId file_id);
|
||||||
|
|
||||||
const VoiceNote *get_voice_note(FileId file_id) const;
|
const VoiceNote *get_voice_note(FileId file_id) const;
|
||||||
@ -88,11 +94,16 @@ class VoiceNotesManager {
|
|||||||
|
|
||||||
void on_voice_note_transcription_updated(FileId file_id);
|
void on_voice_note_transcription_updated(FileId file_id);
|
||||||
|
|
||||||
|
void tear_down() final;
|
||||||
|
|
||||||
Td *td_;
|
Td *td_;
|
||||||
|
ActorShared<> parent_;
|
||||||
|
|
||||||
FlatHashMap<FileId, unique_ptr<VoiceNote>, FileIdHash> voice_notes_;
|
FlatHashMap<FileId, unique_ptr<VoiceNote>, FileIdHash> voice_notes_;
|
||||||
|
|
||||||
FlatHashMap<FileId, vector<Promise<Unit>>, FileIdHash> speech_recognition_queries_;
|
FlatHashMap<FileId, vector<Promise<Unit>>, FileIdHash> speech_recognition_queries_;
|
||||||
FlatHashMap<int64, FileId> pending_voice_note_transcription_queries_;
|
FlatHashMap<int64, FileId> pending_voice_note_transcription_queries_;
|
||||||
|
MultiTimeout voice_note_transcription_timeout_{"VoiceNoteTranscriptionTimeout"};
|
||||||
|
|
||||||
FlatHashMap<FileId, FlatHashSet<FullMessageId, FullMessageIdHash>, FileIdHash> voice_note_messages_;
|
FlatHashMap<FileId, FlatHashSet<FullMessageId, FullMessageIdHash>, FileIdHash> voice_note_messages_;
|
||||||
FlatHashMap<FullMessageId, FileId, FullMessageIdHash> message_voice_notes_;
|
FlatHashMap<FullMessageId, FileId, FullMessageIdHash> message_voice_notes_;
|
||||||
|
@ -424,7 +424,7 @@ class TestDownloadFile : public Task {
|
|||||||
unlink(file.local_->path_).ignore();
|
unlink(file.local_->path_).ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t size = file.size_;
|
size_t size = narrow_cast<size_t>(file.size_);
|
||||||
Random::Xorshift128plus rnd(123);
|
Random::Xorshift128plus rnd(123);
|
||||||
|
|
||||||
size_t begin = 0;
|
size_t begin = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user