Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef COGROB_CLOUD_SPEECH_GOOGLE_SPEECH_H_
00028 #define COGROB_CLOUD_SPEECH_GOOGLE_SPEECH_H_
00029
00030 #include <grpc++/grpc++.h>
00031 #include <atomic>
00032 #include <chrono>
00033 #include <memory>
00034 #include <thread>
00035 #include <string>
00036 #include <vector>
00037
00038 #include "cogrob/cloud/speech/google_speech_interface.h"
00039 #include "cogrob/cloud/speech/proto/recognition_result.pb.h"
00040 #include "google/cloud/speech/v1/cloud_speech.grpc.pb.h"
00041
00042 namespace cogrob {
00043 namespace cloud {
00044 namespace speech {
00045
00046 class GoogleSpeechRecognizer : public GoogleSpeechRecognizerInterface {
00047 public:
00048 GoogleSpeechRecognizer();
00049 ~GoogleSpeechRecognizer() override;
00050
00051
00052
00053 util::Status StartRecognize(AudioQueue* audio_queue,
00054 util::SimpleThreadSafeQueue<RecognitionResult>* result_queue,
00055 const std::vector<std::string>& hints, int max_audio_seconds,
00056 int max_wait_seconds, int max_alternatives) override;
00057
00058
00059 bool IsRunning() override;
00060
00061
00062 util::StatusOr<RecognitionResult> GetLastResult() override;
00063
00064
00065 util::Status Wait() override;
00066
00067
00068 util::Status Stop() override;
00069
00070 private:
00071
00072 void RecognitionThread(AudioQueue* audio_queue,
00073 util::SimpleThreadSafeQueue<RecognitionResult>* result_queue,
00074 const std::vector<std::string>& hints, int max_audio_seconds,
00075 int max_wait_seconds, int max_alternatives);
00076
00077 std::mutex general_mutex_;
00078 std::shared_ptr<grpc::ChannelInterface> channel_;
00079 std::unique_ptr<::google::cloud::speech::v1::Speech::Stub> gspeech_stub_;
00080 std::atomic_bool stop_flag_ {false};
00081 std::atomic_bool done_flag_ {false};
00082 std::unique_ptr<std::thread> thread_;
00083 util::StatusOr<RecognitionResult> latest_result_;
00084 };
00085
00086 }
00087 }
00088 }
00089
00090 #endif // COGROB_CLOUD_SPEECH_GOOGLE_SPEECH_H_