Update trial parameters after speech recognition.
This commit is contained in:
parent
fa6b61d764
commit
50a360c147
@ -446,7 +446,7 @@ void DeviceTokenManager::on_result(NetQueryPtr net_query) {
|
||||
if (!G()->is_expected_error(error)) {
|
||||
LOG(ERROR) << "Failed to " << info.state << " device: " << error;
|
||||
} else {
|
||||
retry_after = Global::get_retry_after(error.code(), error.message());
|
||||
retry_after = Global::get_retry_after(error);
|
||||
}
|
||||
info.promise.set_error(r_flag.move_as_error());
|
||||
} else {
|
||||
|
@ -510,6 +510,10 @@ class Global final : public ActorContext {
|
||||
|
||||
static int32 get_retry_after(int32 error_code, Slice error_message);
|
||||
|
||||
static int32 get_retry_after(const Status &error) {
|
||||
return get_retry_after(error.code(), error.message());
|
||||
}
|
||||
|
||||
const std::vector<std::shared_ptr<NetStatsCallback>> &get_net_stats_file_callbacks() {
|
||||
return net_stats_file_callbacks_;
|
||||
}
|
||||
|
@ -151,6 +151,10 @@ void TranscriptionManager::on_update_trial_parameters(int32 weekly_number, int32
|
||||
new_trial_parameters.duration_max_ = max(0, duration_max);
|
||||
new_trial_parameters.cooldown_until_ = max(0, cooldown_until);
|
||||
new_trial_parameters.left_tries_ = trial_parameters_.left_tries_;
|
||||
set_trial_parameters(new_trial_parameters);
|
||||
}
|
||||
|
||||
void TranscriptionManager::set_trial_parameters(TrialParameters new_trial_parameters) {
|
||||
new_trial_parameters.update_left_tries();
|
||||
if (new_trial_parameters == trial_parameters_) {
|
||||
return;
|
||||
@ -246,11 +250,19 @@ void TranscriptionManager::recognize_speech(MessageFullId message_full_id, Promi
|
||||
|
||||
void TranscriptionManager::on_transcribed_audio(
|
||||
FileInfo file_info, Result<telegram_api::object_ptr<telegram_api::messages_transcribedAudio>> r_audio) {
|
||||
if (G()->close_flag()) {
|
||||
if (G()->close_flag() || !td_->auth_manager_->is_authorized()) {
|
||||
return;
|
||||
}
|
||||
if (r_audio.is_error()) {
|
||||
return on_transcribed_audio_update(file_info, true, r_audio.move_as_error());
|
||||
auto retry_after = Global::get_retry_after(r_audio.error());
|
||||
on_transcribed_audio_update(file_info, true, r_audio.move_as_error());
|
||||
if (retry_after > 0) {
|
||||
TrialParameters new_trial_parameters = trial_parameters_;
|
||||
new_trial_parameters.cooldown_until_ = G()->unix_time() + retry_after;
|
||||
new_trial_parameters.left_tries_ = 0;
|
||||
set_trial_parameters(new_trial_parameters);
|
||||
}
|
||||
return;
|
||||
}
|
||||
auto audio = r_audio.move_as_ok();
|
||||
if (audio->transcription_id_ == 0) {
|
||||
@ -261,12 +273,19 @@ void TranscriptionManager::on_transcribed_audio(
|
||||
update->transcription_id_ = audio->transcription_id_;
|
||||
update->pending_ = audio->pending_;
|
||||
on_transcribed_audio_update(file_info, true, std::move(update));
|
||||
|
||||
if ((audio->flags_ & telegram_api::messages_transcribedAudio::TRIAL_REMAINS_NUM_MASK) != 0) {
|
||||
TrialParameters new_trial_parameters = trial_parameters_;
|
||||
new_trial_parameters.cooldown_until_ = audio->trial_remains_num_ > 0 ? 0 : audio->trial_remains_until_date_;
|
||||
new_trial_parameters.left_tries_ = audio->trial_remains_num_;
|
||||
set_trial_parameters(new_trial_parameters);
|
||||
}
|
||||
}
|
||||
|
||||
void TranscriptionManager::on_transcribed_audio_update(
|
||||
FileInfo file_info, bool is_initial,
|
||||
Result<telegram_api::object_ptr<telegram_api::updateTranscribedAudio>> r_update) {
|
||||
if (G()->close_flag()) {
|
||||
if (G()->close_flag() || !td_->auth_manager_->is_authorized()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -59,6 +59,25 @@ class TranscriptionManager final : public Actor {
|
||||
private:
|
||||
static constexpr int32 AUDIO_TRANSCRIPTION_TIMEOUT = 60;
|
||||
|
||||
struct TrialParameters {
|
||||
int32 weekly_number_ = 0;
|
||||
int32 duration_max_ = 0;
|
||||
int32 left_tries_ = 0;
|
||||
int32 cooldown_until_ = 0;
|
||||
|
||||
void update_left_tries();
|
||||
|
||||
td_api::object_ptr<td_api::updateSpeechRecognitionTrial> get_update_speech_recognition_trial_object() const;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const;
|
||||
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser);
|
||||
};
|
||||
|
||||
friend bool operator==(const TrialParameters &lhs, const TrialParameters &rhs);
|
||||
|
||||
void tear_down() final;
|
||||
|
||||
static void on_pending_audio_transcription_timeout_callback(void *td, int64 transcription_id);
|
||||
@ -67,6 +86,8 @@ class TranscriptionManager final : public Actor {
|
||||
|
||||
void load_trial_parameters();
|
||||
|
||||
void set_trial_parameters(TrialParameters new_trial_parameters);
|
||||
|
||||
void save_trial_parameters();
|
||||
|
||||
void send_update_speech_recognition_trial() const;
|
||||
@ -91,25 +112,6 @@ class TranscriptionManager final : public Actor {
|
||||
|
||||
void on_pending_audio_transcription_failed(int64 transcription_id, Status &&error);
|
||||
|
||||
struct TrialParameters {
|
||||
int32 weekly_number_ = 0;
|
||||
int32 duration_max_ = 0;
|
||||
int32 left_tries_ = 0;
|
||||
int32 cooldown_until_ = 0;
|
||||
|
||||
void update_left_tries();
|
||||
|
||||
td_api::object_ptr<td_api::updateSpeechRecognitionTrial> get_update_speech_recognition_trial_object() const;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const;
|
||||
|
||||
template <class ParserT>
|
||||
void parse(ParserT &parser);
|
||||
};
|
||||
|
||||
friend bool operator==(const TrialParameters &lhs, const TrialParameters &rhs);
|
||||
|
||||
Td *td_;
|
||||
ActorShared<> parent_;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user