Proxy speech recognition methods through MessagesManager.

This commit is contained in:
levlam 2022-10-19 17:56:18 +03:00
parent 5e0103c442
commit c941f488a0
6 changed files with 53 additions and 18 deletions

View File

@ -6173,4 +6173,24 @@ void update_used_hashtags(Td *td, const MessageContent *content) {
}
}
void recognize_message_content_speech(Td *td, const MessageContent *content, FullMessageId full_message_id,
Promise<Unit> &&promise) {
switch (content->get_type()) {
case MessageContentType::VoiceNote:
return td->voice_notes_manager_->recognize_speech(full_message_id, std::move(promise));
default:
return promise.set_error(Status::Error(400, "Invalid message specified"));
}
}
void rate_message_content_speech_recognition(Td *td, const MessageContent *content, FullMessageId full_message_id,
bool is_good, Promise<Unit> &&promise) {
switch (content->get_type()) {
case MessageContentType::VoiceNote:
return td->voice_notes_manager_->rate_speech_recognition(full_message_id, is_good, std::move(promise));
default:
return promise.set_error(Status::Error(400, "Invalid message specified"));
}
}
} // namespace td

View File

@ -264,4 +264,10 @@ void on_dialog_used(TopDialogCategory category, DialogId dialog_id, int32 date);
void update_used_hashtags(Td *td, const MessageContent *content);
void recognize_message_content_speech(Td *td, const MessageContent *content, FullMessageId full_message_id,
Promise<Unit> &&promise);
void rate_message_content_speech_recognition(Td *td, const MessageContent *content, FullMessageId full_message_id,
bool is_good, Promise<Unit> &&promise);
} // namespace td

View File

@ -18822,6 +18822,24 @@ void MessagesManager::translate_text(const string &text, const string &from_lang
td_->create_handler<TranslateTextQuery>(std::move(promise))->send(text, from_language_code, to_language_code);
}
void MessagesManager::recognize_speech(FullMessageId full_message_id, Promise<Unit> &&promise) {
auto m = get_message_force(full_message_id, "recognize_speech");
if (m == nullptr) {
return promise.set_error(Status::Error(400, "Message not found"));
}
recognize_message_content_speech(td_, m->content.get(), full_message_id, std::move(promise));
}
void MessagesManager::rate_speech_recognition(FullMessageId full_message_id, bool is_good, Promise<Unit> &&promise) {
auto m = get_message_force(full_message_id, "rate_speech_recognition");
if (m == nullptr) {
return promise.set_error(Status::Error(400, "Message not found"));
}
rate_message_content_speech_recognition(td_, m->content.get(), full_message_id, is_good, std::move(promise));
}
void MessagesManager::get_dialog_info_full(DialogId dialog_id, Promise<Unit> &&promise, const char *source) {
switch (dialog_id.get_type()) {
case DialogType::User:

View File

@ -649,6 +649,10 @@ class MessagesManager final : public Actor {
void translate_text(const string &text, const string &from_language_code, const string &to_language_code,
Promise<td_api::object_ptr<td_api::text>> &&promise);
void recognize_speech(FullMessageId full_message_id, Promise<Unit> &&promise);
void rate_speech_recognition(FullMessageId full_message_id, bool is_good, Promise<Unit> &&promise);
bool is_message_edited_recently(FullMessageId full_message_id, int32 seconds);
bool is_deleted_secret_chat(DialogId dialog_id) const;

View File

@ -4689,15 +4689,14 @@ void Td::on_request(uint64 id, td_api::translateText &request) {
void Td::on_request(uint64 id, const td_api::recognizeSpeech &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
voice_notes_manager_->recognize_speech({DialogId(request.chat_id_), MessageId(request.message_id_)},
std::move(promise));
messages_manager_->recognize_speech({DialogId(request.chat_id_), MessageId(request.message_id_)}, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::rateSpeechRecognition &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
voice_notes_manager_->rate_speech_recognition({DialogId(request.chat_id_), MessageId(request.message_id_)},
request.is_good_, std::move(promise));
messages_manager_->rate_speech_recognition({DialogId(request.chat_id_), MessageId(request.message_id_)},
request.is_good_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getFile &request) {

View File

@ -272,14 +272,8 @@ void VoiceNotesManager::unregister_voice_note(FileId voice_note_file_id, FullMes
}
void VoiceNotesManager::recognize_speech(FullMessageId full_message_id, Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_message_force(full_message_id, "recognize_speech")) {
return promise.set_error(Status::Error(400, "Message not found"));
}
auto it = message_voice_notes_.find(full_message_id);
if (it == message_voice_notes_.end()) {
return promise.set_error(Status::Error(400, "Invalid message specified"));
}
CHECK(it != message_voice_notes_.end());
auto file_id = it->second;
auto voice_note = get_voice_note(file_id);
@ -396,14 +390,8 @@ void VoiceNotesManager::on_voice_note_transcription_completed(FileId file_id) {
}
void VoiceNotesManager::rate_speech_recognition(FullMessageId full_message_id, bool is_good, Promise<Unit> &&promise) {
if (!td_->messages_manager_->have_message_force(full_message_id, "rate_speech_recognition")) {
return promise.set_error(Status::Error(400, "Message not found"));
}
auto it = message_voice_notes_.find(full_message_id);
if (it == message_voice_notes_.end()) {
return promise.set_error(Status::Error(400, "Invalid message specified"));
}
CHECK(it != message_voice_notes_.end());
auto file_id = it->second;
auto voice_note = get_voice_note(file_id);