Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[websocket] 8k and 16k support #2505

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions runtime/core/bin/websocket_client_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ DEFINE_int32(port, 10086, "port of websocket server");
DEFINE_int32(nbest, 1, "n-best of decode result");
DEFINE_string(wav_path, "", "test wav file path");
DEFINE_bool(continuous_decoding, false, "continuous decoding mode");
DEFINE_int32(sr, 16000, "audio sample rate");

int main(int argc, char* argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, false);
google::InitGoogleLogging(argv[0]);
wenet::WebSocketClient client(FLAGS_hostname, FLAGS_port);
client.set_nbest(FLAGS_nbest);
client.set_sr(FLAGS_sr);
client.set_continuous_decoding(FLAGS_continuous_decoding);
client.SendStartSignal();

wenet::WavReader wav_reader(FLAGS_wav_path);
const int sample_rate = 16000;
// Only support 16K
int sample_rate = client.sample_rate_;
pengzhendong marked this conversation as resolved.
Show resolved Hide resolved
CHECK_EQ(wav_reader.sample_rate(), sample_rate);
const int num_samples = wav_reader.num_samples();
// Send data every 0.5 second
Expand Down
3 changes: 2 additions & 1 deletion runtime/core/websocket/websocket_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using tcp = boost::asio::ip::tcp; // from <boost/asio/ip/tcp.hpp>
class WebSocketClient {
public:
WebSocketClient(const std::string& host, int port);

int sample_rate_;
void SendTextData(const std::string& data);
void SendBinaryData(const void* data, size_t size);
void ReadLoopFunc();
Expand All @@ -47,6 +47,7 @@ class WebSocketClient {
void SendStartSignal();
void SendEndSignal();
void set_nbest(int nbest) { nbest_ = nbest; }
void set_sr(int sr) { sample_rate_ = sr; }
void set_continuous_decoding(bool continuous_decoding) {
continuous_decoding_ = continuous_decoding;
}
Expand Down
Loading