1 Star 2 Fork 0

ppnt/whisper-cpp-server

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
stream_components_output.h 2.55 KB
一键复制 编辑 原始数据 按行查看 历史
李通 提交于 2023-11-21 22:21 +08:00 . change directory
#ifndef WHISPER_STREAM_COMPONENTS_OUTPUT_H
#define WHISPER_STREAM_COMPONENTS_OUTPUT_H
#include <memory>
#include <iostream>
#include "whisper.h"
#include "stream_components_params.h"
/**
* Classes that support componentization of the service.
* These classes support encoding the service state and the transcription
* into JSON (and in the future, into other formats such as msgpack,
* flexbuffers, etc.)
*/
namespace stream_components {
class WhisperEncoder {
public:
virtual void reset() = 0;
virtual void start_arr(const char *name) = 0;
virtual void end_arr(bool end) = 0;
virtual void start_obj(const char *name) = 0;
virtual void end_obj(bool end) = 0;
virtual void start_value(const char *name) = 0;
virtual void value_s(const char *name, const char *val, bool end) = 0;
virtual void end_value(bool end) = 0;
virtual void value_i(const char *name, const int64_t val, bool end) = 0;
virtual void value_b(const char *name, const bool val, bool end) = 0;
virtual void value_f(const char *name, const float val, bool end) = 0;
};
class WhisperEncoderJSON : public WhisperEncoder {
public:
WhisperEncoderJSON(std::ostream &os) : fout(os) {}
void reset() override { indent = 0; }
void start_arr(const char *name) override;
void end_arr(bool end) override;
void start_obj(const char *name) override;
void end_obj(bool end) override;
void start_value(const char *name) override;
void value_s(const char *name, const char *val, bool end) override;
void end_value(bool end) override;
void value_i(const char *name, const int64_t val, bool end) override;
void value_b(const char *name, const bool val, bool end) override;
void value_f(const char *name, const float val, bool end) override;
protected:
std::ostream &fout;
int indent = 0;
void doindent();
};
class WhisperStreamOutput {
public:
WhisperStreamOutput(
struct whisper_context *ctx,
const service_params &params);
static void encode_server(WhisperEncoder &encoder, const service_params &params, struct whisper_context *ctx);
void encode_transcription(WhisperEncoder &encoder) const;
static void to_json(std::ostream &os, const service_params &params, struct whisper_context *ctx);
void transcription_to_json(std::ostream &os) const;
protected:
struct whisper_context *ctx;
const service_params params;
};
using WhisperOutputPtr = std::shared_ptr<WhisperStreamOutput>;
} // namespace stream_components
#endif // WHISPER_STREAM_COMPONENTS_OUTPUT_H
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML
1
https://gitee.com/ppnt/whisper-cpp-server.git
git@gitee.com:ppnt/whisper-cpp-server.git
ppnt
whisper-cpp-server
whisper-cpp-server
main

搜索帮助