audio.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #ifndef AUDIO_H
  2. #define AUDIO_H
  3. #include <queue>
  4. #include <stdint.h>
  5. #include "vad-model.h"
  6. #include "offline-stream.h"
  7. #ifndef WAV_HEADER_SIZE
  8. #define WAV_HEADER_SIZE 44
  9. #endif
  10. using namespace std;
  11. namespace funasr {
  12. class AudioFrame {
  13. private:
  14. int start;
  15. int end;
  16. int len;
  17. public:
  18. AudioFrame();
  19. AudioFrame(int len);
  20. ~AudioFrame();
  21. int SetStart(int val);
  22. int SetEnd(int val);
  23. int GetStart();
  24. int GetLen();
  25. int Disp();
  26. };
  27. class Audio {
  28. private:
  29. float *speech_data=nullptr;
  30. int16_t *speech_buff=nullptr;
  31. char* speech_char=nullptr;
  32. int speech_len;
  33. int speech_align_len;
  34. int offset;
  35. float align_size;
  36. int data_type;
  37. queue<AudioFrame *> frame_queue;
  38. public:
  39. Audio(int data_type);
  40. Audio(int data_type, int size);
  41. ~Audio();
  42. void Disp();
  43. void WavResample(int32_t sampling_rate, const float *waveform, int32_t n);
  44. bool LoadWav(const char* buf, int n_len, int32_t* sampling_rate);
  45. bool LoadWav(const char* filename, int32_t* sampling_rate);
  46. bool LoadWav2Char(const char* filename, int32_t* sampling_rate);
  47. bool LoadPcmwav(const char* buf, int n_file_len, int32_t* sampling_rate);
  48. bool LoadPcmwav(const char* filename, int32_t* sampling_rate);
  49. bool LoadPcmwav2Char(const char* filename, int32_t* sampling_rate);
  50. int FetchChunck(float *&dout, int len);
  51. int Fetch(float *&dout, int &len, int &flag);
  52. void Padding();
  53. void Split(OfflineStream* offline_streamj);
  54. void Split(VadModel* vad_obj, vector<std::vector<int>>& vad_segments, bool input_finished=true);
  55. float GetTimeLen();
  56. int GetQueueSize() { return (int)frame_queue.size(); }
  57. char* GetSpeechChar(){return speech_char;}
  58. int GetSpeechLen(){return speech_len;}
  59. };
  60. } // namespace funasr
  61. #endif