2023-11-21 13:14:26 +01:00
|
|
|
//
|
|
|
|
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2023
|
|
|
|
//
|
|
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
//
|
|
|
|
#pragma once
|
|
|
|
|
2023-11-21 17:27:25 +01:00
|
|
|
#include "td/telegram/td_api.h"
|
2023-11-21 18:32:23 +01:00
|
|
|
#include "td/telegram/telegram_api.h"
|
2023-11-21 17:27:25 +01:00
|
|
|
|
2023-11-21 13:14:26 +01:00
|
|
|
#include "td/actor/actor.h"
|
2023-11-21 18:32:23 +01:00
|
|
|
#include "td/actor/MultiTimeout.h"
|
2023-11-21 13:14:26 +01:00
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
2023-11-21 18:32:23 +01:00
|
|
|
#include "td/utils/FlatHashMap.h"
|
|
|
|
#include "td/utils/Status.h"
|
|
|
|
|
|
|
|
#include <functional>
|
2023-11-21 13:14:26 +01:00
|
|
|
|
|
|
|
namespace td {
|
|
|
|
|
|
|
|
class Td;
|
|
|
|
|
|
|
|
class TranscriptionManager final : public Actor {
|
|
|
|
public:
|
|
|
|
TranscriptionManager(Td *td, ActorShared<> parent);
|
|
|
|
|
2023-11-21 17:27:25 +01:00
|
|
|
void on_update_trial_parameters(int32 weekly_number, int32 duration_max, int32 cooldown_until);
|
|
|
|
|
2023-11-21 18:32:23 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
void on_update_transcribed_audio(telegram_api::object_ptr<telegram_api::updateTranscribedAudio> &&update);
|
|
|
|
|
2023-11-21 17:31:27 +01:00
|
|
|
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
|
|
|
|
|
2023-11-21 13:14:26 +01:00
|
|
|
private:
|
2023-11-21 18:32:23 +01:00
|
|
|
static constexpr int32 AUDIO_TRANSCRIPTION_TIMEOUT = 60;
|
|
|
|
|
2023-11-21 13:14:26 +01:00
|
|
|
void tear_down() final;
|
|
|
|
|
2023-11-21 18:32:23 +01:00
|
|
|
static void on_pending_audio_transcription_timeout_callback(void *td, int64 transcription_id);
|
|
|
|
|
2023-11-21 18:08:05 +01:00
|
|
|
static string get_trial_parameters_database_key();
|
|
|
|
|
|
|
|
void load_trial_parameters();
|
|
|
|
|
|
|
|
void save_trial_parameters();
|
|
|
|
|
2023-11-21 17:27:25 +01:00
|
|
|
void send_update_speech_recognition_trial() const;
|
|
|
|
|
|
|
|
td_api::object_ptr<td_api::updateSpeechRecognitionTrial> get_update_speech_recognition_trial_object() const;
|
|
|
|
|
2023-11-21 18:32:23 +01:00
|
|
|
void on_pending_audio_transcription_failed(int64 transcription_id, Status &&error);
|
|
|
|
|
2023-11-21 17:51:07 +01:00
|
|
|
struct TrialParameters {
|
|
|
|
int32 weekly_number_ = 0;
|
|
|
|
int32 duration_max_ = 0;
|
|
|
|
int32 left_tries_ = 0;
|
|
|
|
int32 cooldown_until_ = 0;
|
|
|
|
|
2023-11-21 18:08:05 +01:00
|
|
|
void update_left_tries();
|
|
|
|
|
2023-11-21 17:51:07 +01:00
|
|
|
td_api::object_ptr<td_api::updateSpeechRecognitionTrial> get_update_speech_recognition_trial_object() const;
|
2023-11-21 18:08:05 +01:00
|
|
|
|
|
|
|
template <class StorerT>
|
|
|
|
void store(StorerT &storer) const;
|
|
|
|
|
|
|
|
template <class ParserT>
|
|
|
|
void parse(ParserT &parser);
|
2023-11-21 17:51:07 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
friend bool operator==(const TrialParameters &lhs, const TrialParameters &rhs);
|
|
|
|
|
2023-11-21 13:14:26 +01:00
|
|
|
Td *td_;
|
|
|
|
ActorShared<> parent_;
|
2023-11-21 17:27:25 +01:00
|
|
|
|
2023-11-21 17:51:07 +01:00
|
|
|
TrialParameters trial_parameters_;
|
2023-11-21 18:32:23 +01:00
|
|
|
|
|
|
|
FlatHashMap<int64, TranscribedAudioHandler> pending_audio_transcriptions_;
|
|
|
|
MultiTimeout pending_audio_transcription_timeout_{"PendingAudioTranscriptionTimeout"};
|
2023-11-21 13:14:26 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace td
|