Files
xiaozhi-esp32/main/OpusEncoder.h

30 lines
641 B
C
Raw Normal View History

2024-08-31 18:00:23 +08:00
#ifndef _OPUS_ENCODER_H_
#define _OPUS_ENCODER_H_
#include <functional>
#include <string>
2024-09-01 10:37:02 +08:00
#include <vector>
#include <memory>
#include "lwip/sockets.h"
2024-08-31 18:00:23 +08:00
#include "opus.h"
2024-09-01 10:37:02 +08:00
2024-08-31 18:00:23 +08:00
class OpusEncoder {
public:
OpusEncoder();
~OpusEncoder();
void Configure(int sample_rate, int channels, int duration_ms = 60);
2024-09-01 10:37:02 +08:00
void Encode(const iovec pcm, std::function<void(const iovec opus)> handler);
2024-08-31 18:00:23 +08:00
bool IsBufferEmpty() const { return in_buffer_.empty(); }
private:
struct OpusEncoder* audio_enc_ = nullptr;
int frame_size_;
2024-09-01 10:37:02 +08:00
std::vector<uint8_t> out_buffer_;
std::vector<int16_t> in_buffer_;
2024-08-31 18:00:23 +08:00
};
#endif // _OPUS_ENCODER_H_