Add rateSpeechRecognition.
This commit is contained in:
parent
d9a9693747
commit
b56b778660
|
@ -4823,6 +4823,9 @@ translateText text:string from_language_code:string to_language_code:string = Te
|
||||||
//@message_id Identifier of the message
|
//@message_id Identifier of the message
|
||||||
recognizeSpeech chat_id:int53 message_id:int53 = Ok;
|
recognizeSpeech chat_id:int53 message_id:int53 = Ok;
|
||||||
|
|
||||||
|
//@description Rates recognized speech in a voice note message @chat_id Identifier of the chat to which the message belongs @message_id Identifier of the message @is_good Pass true if the speech recognition is good
|
||||||
|
rateSpeechRecognition chat_id:int53 message_id:int53 is_good:Bool = Ok;
|
||||||
|
|
||||||
|
|
||||||
//@description Returns list of message sender identifiers, which can be used to send messages in a chat @chat_id Chat identifier
|
//@description Returns list of message sender identifiers, which can be used to send messages in a chat @chat_id Chat identifier
|
||||||
getChatAvailableMessageSenders chat_id:int53 = MessageSenders;
|
getChatAvailableMessageSenders chat_id:int53 = MessageSenders;
|
||||||
|
|
|
@ -4804,6 +4804,13 @@ void Td::on_request(uint64 id, const td_api::recognizeSpeech &request) {
|
||||||
std::move(promise));
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::getFile &request) {
|
void Td::on_request(uint64 id, const td_api::getFile &request) {
|
||||||
send_closure(actor_id(this), &Td::send_result, id, file_manager_->get_file_object(FileId(request.file_id_, 0)));
|
send_closure(actor_id(this), &Td::send_result, id, file_manager_->get_file_object(FileId(request.file_id_, 0)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -534,6 +534,8 @@ class Td final : public Actor {
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::recognizeSpeech &request);
|
void on_request(uint64 id, const td_api::recognizeSpeech &request);
|
||||||
|
|
||||||
|
void on_request(uint64 id, const td_api::rateSpeechRecognition &request);
|
||||||
|
|
||||||
void on_request(uint64 id, const td_api::getFile &request);
|
void on_request(uint64 id, const td_api::getFile &request);
|
||||||
|
|
||||||
void on_request(uint64 id, td_api::getRemoteFile &request);
|
void on_request(uint64 id, td_api::getRemoteFile &request);
|
||||||
|
|
|
@ -58,6 +58,42 @@ class TranscribeAudioQuery final : public Td::ResultHandler {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class RateTranscribedAudioQuery final : public Td::ResultHandler {
|
||||||
|
Promise<Unit> promise_;
|
||||||
|
DialogId dialog_id_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit RateTranscribedAudioQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void send(FullMessageId full_message_id, int64 transcription_id, bool is_good) {
|
||||||
|
dialog_id_ = full_message_id.get_dialog_id();
|
||||||
|
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
|
||||||
|
if (input_peer == nullptr) {
|
||||||
|
return on_error(Status::Error(400, "Can't access the chat"));
|
||||||
|
}
|
||||||
|
send_query(G()->net_query_creator().create(telegram_api::messages_rateTranscribedAudio(
|
||||||
|
std::move(input_peer), full_message_id.get_message_id().get_server_message_id().get(), transcription_id,
|
||||||
|
is_good)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_result(BufferSlice packet) final {
|
||||||
|
auto result_ptr = fetch_result<telegram_api::messages_rateTranscribedAudio>(packet);
|
||||||
|
if (result_ptr.is_error()) {
|
||||||
|
return on_error(result_ptr.move_as_error());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool result = result_ptr.ok();
|
||||||
|
LOG(INFO) << "Receive result for RateTranscribedAudioQuery: " << result;
|
||||||
|
promise_.set_value(Unit());
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_error(Status status) final {
|
||||||
|
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "RateTranscribedAudioQuery");
|
||||||
|
promise_.set_error(std::move(status));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
VoiceNotesManager::VoiceNotesManager(Td *td) : td_(td) {
|
VoiceNotesManager::VoiceNotesManager(Td *td) : td_(td) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,6 +358,27 @@ void VoiceNotesManager::on_voice_note_transcription_updated(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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
auto file_id = it->second;
|
||||||
|
auto voice_note = get_voice_note(file_id);
|
||||||
|
CHECK(voice_note != nullptr);
|
||||||
|
if (!voice_note->is_transcribed) {
|
||||||
|
return promise.set_value(Unit());
|
||||||
|
}
|
||||||
|
CHECK(voice_note->transcription_id != 0);
|
||||||
|
td_->create_handler<RateTranscribedAudioQuery>(std::move(promise))
|
||||||
|
->send(full_message_id, voice_note->transcription_id, is_good);
|
||||||
|
}
|
||||||
|
|
||||||
SecretInputMedia VoiceNotesManager::get_secret_input_media(FileId voice_note_file_id,
|
SecretInputMedia VoiceNotesManager::get_secret_input_media(FileId voice_note_file_id,
|
||||||
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
||||||
const string &caption, int32 layer) const {
|
const string &caption, int32 layer) const {
|
||||||
|
|
|
@ -40,6 +40,8 @@ class VoiceNotesManager {
|
||||||
|
|
||||||
void recognize_speech(FullMessageId full_message_id, Promise<Unit> &&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);
|
||||||
|
|
||||||
void on_update_transcribed_audio(string &&text, int64 transcription_id, bool is_final);
|
void on_update_transcribed_audio(string &&text, int64 transcription_id, bool is_final);
|
||||||
|
|
||||||
void on_voice_note_transcribed(FileId file_id, string &&text, int64 transcription_id, bool is_final);
|
void on_voice_note_transcribed(FileId file_id, string &&text, int64 transcription_id, bool is_final);
|
||||||
|
|
|
@ -2894,6 +2894,12 @@ class CliClient final : public Actor {
|
||||||
MessageId message_id;
|
MessageId message_id;
|
||||||
get_args(args, chat_id, message_id);
|
get_args(args, chat_id, message_id);
|
||||||
send_request(td_api::make_object<td_api::recognizeSpeech>(chat_id, message_id));
|
send_request(td_api::make_object<td_api::recognizeSpeech>(chat_id, message_id));
|
||||||
|
} else if (op == "rsr") {
|
||||||
|
ChatId chat_id;
|
||||||
|
MessageId message_id;
|
||||||
|
bool is_good;
|
||||||
|
get_args(args, chat_id, message_id, is_good);
|
||||||
|
send_request(td_api::make_object<td_api::rateSpeechRecognition>(chat_id, message_id, is_good));
|
||||||
} else if (op == "gf" || op == "GetFile") {
|
} else if (op == "gf" || op == "GetFile") {
|
||||||
FileId file_id;
|
FileId file_id;
|
||||||
get_args(args, file_id);
|
get_args(args, file_id);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user