Handle full messages.transcribedAudio.
This commit is contained in:
parent
ec109dfd4a
commit
fa6b61d764
@ -20,11 +20,11 @@ namespace td {
|
||||
|
||||
class TranscribeAudioQuery final : public Td::ResultHandler {
|
||||
DialogId dialog_id_;
|
||||
std::function<void(Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>>)> handler_;
|
||||
std::function<void(Result<telegram_api::object_ptr<telegram_api::messages_transcribedAudio>>)> handler_;
|
||||
|
||||
public:
|
||||
void send(MessageFullId message_full_id,
|
||||
std::function<void(Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>>)> &&handler) {
|
||||
std::function<void(Result<telegram_api::object_ptr<telegram_api::messages_transcribedAudio>>)> &&handler) {
|
||||
dialog_id_ = message_full_id.get_dialog_id();
|
||||
handler_ = std::move(handler);
|
||||
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
|
||||
@ -43,14 +43,7 @@ class TranscribeAudioQuery final : public Td::ResultHandler {
|
||||
|
||||
auto result = result_ptr.move_as_ok();
|
||||
LOG(INFO) << "Receive result for TranscribeAudioQuery: " << to_string(result);
|
||||
if (result->transcription_id_ == 0) {
|
||||
return on_error(Status::Error(500, "Receive no recognition identifier"));
|
||||
}
|
||||
auto update = telegram_api::make_object<telegram_api::updateTranscribedAudio>();
|
||||
update->text_ = std::move(result->text_);
|
||||
update->transcription_id_ = result->transcription_id_;
|
||||
update->pending_ = result->pending_;
|
||||
handler_(std::move(update));
|
||||
handler_(std::move(result));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
@ -97,7 +90,7 @@ class RateTranscribedAudioQuery final : public Td::ResultHandler {
|
||||
|
||||
bool TranscriptionInfo::recognize_speech(
|
||||
Td *td, MessageFullId message_full_id, Promise<Unit> &&promise,
|
||||
std::function<void(Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>>)> &&handler) {
|
||||
std::function<void(Result<telegram_api::object_ptr<telegram_api::messages_transcribedAudio>>)> &&handler) {
|
||||
if (is_transcribed_) {
|
||||
promise.set_value(Unit());
|
||||
return false;
|
||||
|
@ -36,7 +36,7 @@ class TranscriptionInfo {
|
||||
|
||||
bool recognize_speech(
|
||||
Td *td, MessageFullId message_full_id, Promise<Unit> &&promise,
|
||||
std::function<void(Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>>)> &&handler);
|
||||
std::function<void(Result<telegram_api::object_ptr<telegram_api::messages_transcribedAudio>>)> &&handler);
|
||||
|
||||
vector<Promise<Unit>> on_final_transcription(string &&text, int64 transcription_id);
|
||||
|
||||
|
@ -236,14 +236,33 @@ void TranscriptionManager::recognize_speech(MessageFullId message_full_id, Promi
|
||||
|
||||
auto *transcription_info = get_transcription_info(it->second, true);
|
||||
auto handler = [actor_id = actor_id(this), file_info = it->second](
|
||||
Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>> r_update) {
|
||||
send_closure(actor_id, &TranscriptionManager::on_transcribed_audio_update, file_info, true, std::move(r_update));
|
||||
Result<telegram_api::object_ptr<telegram_api::messages_transcribedAudio>> r_audio) {
|
||||
send_closure(actor_id, &TranscriptionManager::on_transcribed_audio, file_info, std::move(r_audio));
|
||||
};
|
||||
if (transcription_info->recognize_speech(td_, message_full_id, std::move(promise), std::move(handler))) {
|
||||
on_transcription_updated(it->second.second);
|
||||
}
|
||||
}
|
||||
|
||||
void TranscriptionManager::on_transcribed_audio(
|
||||
FileInfo file_info, Result<telegram_api::object_ptr<telegram_api::messages_transcribedAudio>> r_audio) {
|
||||
if (G()->close_flag()) {
|
||||
return;
|
||||
}
|
||||
if (r_audio.is_error()) {
|
||||
return on_transcribed_audio_update(file_info, true, r_audio.move_as_error());
|
||||
}
|
||||
auto audio = r_audio.move_as_ok();
|
||||
if (audio->transcription_id_ == 0) {
|
||||
return on_transcribed_audio_update(file_info, true, Status::Error(500, "Receive no transcription identifier"));
|
||||
}
|
||||
auto update = telegram_api::make_object<telegram_api::updateTranscribedAudio>();
|
||||
update->text_ = std::move(audio->text_);
|
||||
update->transcription_id_ = audio->transcription_id_;
|
||||
update->pending_ = audio->pending_;
|
||||
on_transcribed_audio_update(file_info, true, std::move(update));
|
||||
}
|
||||
|
||||
void TranscriptionManager::on_transcribed_audio_update(
|
||||
FileInfo file_info, bool is_initial,
|
||||
Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>> r_update) {
|
||||
|
@ -77,6 +77,9 @@ class TranscriptionManager final : public Actor {
|
||||
|
||||
TranscriptionInfo *get_transcription_info(const FileInfo &file_info, bool allow_creation);
|
||||
|
||||
void on_transcribed_audio(FileInfo file_info,
|
||||
Result<telegram_api::object_ptr<telegram_api::messages_transcribedAudio>> r_audio);
|
||||
|
||||
using TranscribedAudioHandler =
|
||||
std::function<void(Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>>)>;
|
||||
void subscribe_to_transcribed_audio_updates(int64 transcription_id, TranscribedAudioHandler on_update);
|
||||
|
Loading…
Reference in New Issue
Block a user