26 input_finished_(false) {
32 KALDI_ERR <<
"OnlineSpeexEncoder called but Speex not installed." 33 <<
"You should run tools/extras/install_speex.sh first, then " 34 <<
"re-run configure in src/ and then make Kaldi again.\n";
38 speex_state_ = speex_encoder_init(&speex_wb_mode);
40 speex_encoder_ctl(speex_state_, SPEEX_SET_QUALITY, &tmp);
42 speex_encoder_ctl(speex_state_, SPEEX_SET_SAMPLING_RATE, &tmp);
50 speex_encoder_destroy(speex_state_);
56 if (waveform.
Dim() == 0) {
60 KALDI_ERR <<
"AcceptWaveform called after InputFinished() was called.";
63 KALDI_ERR <<
"Sampling frequency mismatch, expected " 69 appended_wave : waveform);
76 waveform.
Dim()).CopyFromVec(waveform);
80 std::vector<char> spx_bits;
81 Encode(wave_to_use, &spx_bits);
83 if (spx_bits.size() > 0) {
85 spx_bits.begin(), spx_bits.end());
97 std::vector<char> spx_bits;
99 Encode(wave_last, &spx_bits);
102 spx_bits.begin(), spx_bits.end());
107 std::vector<char> *speex_encoder_bits) {
108 if (wave.
Dim() == 0) {
113 int32 has_encode = 0;
115 std::vector<char> encoded_bits;
125 KALDI_ERR <<
"The number of bytes of Speex encoded frame mismatch," 128 nbytes = speex_bits_write(&
speex_bits_, cbits, 200);
131 int32 encoded_bits_len = encoded_bits.size();
132 encoded_bits.resize(encoded_bits_len + nbytes);
133 for (
int32 i = 0;
i < nbytes;
i++) {
134 encoded_bits[
i+encoded_bits_len] = cbits[
i];
152 *speex_encoder_bits = encoded_bits;
161 KALDI_ERR <<
"OnlineSpeexEncoder called but Speex not installed." 162 <<
"You should run tools/extras/install_speex.sh first, then " 163 <<
"re-run configure in src/ and then make Kaldi again.\n";
167 speex_state_ = speex_decoder_init(&speex_wb_mode);
169 speex_decoder_ctl(speex_state_, SPEEX_SET_QUALITY, &tmp);
171 speex_decoder_ctl(speex_state_, SPEEX_SET_SAMPLING_RATE, &tmp);
178 speex_decoder_destroy(speex_state_);
184 if (spx_enc_bits.size() == 0) {
188 std::vector<char> appended_bits;
189 const std::vector<char> &bits_to_use = (speex_bits_remainder_.size() != 0 ?
190 appended_bits : spx_enc_bits);
191 if (speex_bits_remainder_.size() != 0) {
192 appended_bits.insert(appended_bits.end(), speex_bits_remainder_.begin(),
193 speex_bits_remainder_.end());
194 appended_bits.insert(appended_bits.end(), spx_enc_bits.begin(),
197 speex_bits_remainder_.clear();
200 Decode(bits_to_use, &waveform);
201 if (waveform.
Dim() == 0) {
205 int32 last_wav_size = waveform_.Dim();
206 waveform_.Resize(last_wav_size + waveform.
Dim(),
kCopyData);
207 waveform_.Range(last_wav_size, waveform.
Dim()).CopyFromVec(waveform);
219 int32 to_decode = speex_char_bits.size();
220 int32 has_decode = 0;
234 for (
int32 i = 0;
i < speex_decoded_frame_size_;
i++) {
235 (*decoded_wav)(
i+dim) = wav[
i];
243 speex_bits_remainder_.insert(speex_bits_remainder_.end(),
244 speex_char_bits.begin() + has_decode, speex_char_bits.end());
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
std::vector< char > speex_encoded_char_bits_
Vector< BaseFloat > waveform_remainder_
void AcceptWaveform(int32 sample_rate, const VectorBase< BaseFloat > &waveform)
void Resize(MatrixIndexT length, MatrixResizeType resize_type=kSetZero)
Set vector to a specified size (can be zero).
void AcceptSpeexBits(const std::vector< char > &spx_enc_bits)
int32 speex_wave_frame_size
In samples.
Real * Data()
Returns a pointer to the start of the vector's data.
MatrixIndexT Dim() const
Returns the dimension of the vector.
int32 speex_encoded_frame_size_
BaseFloat sample_rate
The sample frequency of the waveform, it decides which Speex mode to use.
A class representing a vector.
void Decode(const std::vector< char > &speex_char_bits, Vector< BaseFloat > *decoded_wav)
#define KALDI_ASSERT(cond)
void Encode(const VectorBase< BaseFloat > &wave, std::vector< char > *speex_encoder_bits)
int32 speex_quality
Ranges from 0 to 10, the higher the quality is better.
Provides a vector abstraction class.
OnlineSpeexDecoder(const SpeexOptions &config)
Represents a non-allocating general vector which can be defined as a sub-vector of higher-level vecto...
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).
int32 speex_bits_frame_size
In bytes.
OnlineSpeexEncoder(const SpeexOptions &config)