// Copyright 2017 Mobvoi Inc. All Rights Reserved. // Author: shtxie@mobvoi.com (Shoutao Xie) #ifndef SDS_UTILS_WAV_UTILS_H_ #define SDS_UTILS_WAV_UTILS_H_ #include #include #include "types.h" namespace mobvoi { namespace sds { struct WavHeader { uint8 riff[4]; // RIFF Header Magic header uint32 chunk_size; // RIFF Chunk Size uint8 wave[4]; // WAVE Header uint8 fmt[4]; // FMT header uint32 subchunk1_size; // Size of the fmt chunk uint16 audio_format; // Audio format 1=PCM,6=mulaw,7=alaw,257=IBM // Mu-Law, 258=IBM A-Law, 259=ADPCM uint16 channel_num; // Number of channels 1=Mono 2=Stereo uint32 samples_per_sec; // Sampling Frequency in Hz uint32 bytes_per_sec; // bytes per second uint16 block_align; // 2=16-bit mono, 4=16-bit stereo uint16 bits_per_sample; // Number of bits per sample uint8 subchunk2_id[4]; // "data" string uint32 subchunk2_size; // Sampled data length }; typedef int (*audio_send_func)(const char* frame, int size); double GetWavDurationMs(const std::string& wav_file); bool ReadWavPcmData(const std::string& wav_file, std::vector* out); void ConvertPCMToWAV(const std::string& pcm, std::string* wav, const int channel = 1, const int rate = 16000, const int bit_depth = 16); class AudioSender { public: AudioSender(int interval_ms, const std::string& audio_file, audio_send_func audio_handler); void StreamingSend(); void DirectlySend(); private: int interval_ms_; std::vector audio_bytes_; audio_send_func audio_handler_; }; } // namespace sds } // namespace mobvoi #endif // SDS_UTILS_WAV_UTILS_H_