#include "common-whisper.h" #include #include #include #include #include #include #ifdef NDEBUG #undef NDEBUG #endif #include static std::vector read_file_bytes(const std::string & path) { std::ifstream input(path, std::ios::binary); assert(input.good()); return std::vector( std::istreambuf_iterator(input), std::istreambuf_iterator()); } static void assert_pcm_nearly_equal(const std::vector & expected, const std::vector & actual) { assert(expected.size() == actual.size()); for (size_t i = 0; i < expected.size(); ++i) { assert(std::fabs(expected[i] - actual[i]) < 1e-6f); } } int main() { const std::string sample_path = SAMPLE_PATH; const std::vector wav_data = read_file_bytes(sample_path); assert(!wav_data.empty()); std::vector pcm_from_file; std::vector> stereo_from_file; assert(read_audio_data(sample_path, pcm_from_file, stereo_from_file, false)); assert(!pcm_from_file.empty()); assert(stereo_from_file.empty()); std::vector pcm_from_memory; std::vector> stereo_from_memory; assert(read_audio_data(wav_data.data(), wav_data.size(), pcm_from_memory, stereo_from_memory, false)); assert(!pcm_from_memory.empty()); assert(stereo_from_memory.empty()); assert_pcm_nearly_equal(pcm_from_file, pcm_from_memory); printf("Decoded %zu bytes from memory into %zu PCM samples\n", wav_data.size(), pcm_from_memory.size()); return 0; }