Instructions to use litert-community/ZONOS3-Mini with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- LiteRT
How to use litert-community/ZONOS3-Mini with LiteRT:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Download host/audio.cpp from litert-community/ZONOS3-Mini: direct link, hf CLI and curl.
- Browser
- Download file 3.29 kB
-
https://huggingface.co/litert-community/ZONOS3-Mini/resolve/main/host/audio.cpp
- Command line
-
hf download hf://litert-community/ZONOS3-Mini/host/audio.cpp
-
curl -L -o audio.cpp https://huggingface.co/litert-community/ZONOS3-Mini/resolve/main/host/audio.cpp
3.29 kB
| static Floats branch_audio(const Floats& head, int frames, int fft, int offset, const Floats& window) { | |
| const int hop = 184, rows = frames * 16, bins = fft/2 + 1; | |
| Floats sum((rows-1)*hop + fft), env(sum.size()), block(fft); | |
| std::vector<std::complex<float>> spectrum(bins); | |
| // Reverse window blocks to match istft_np's increasing block-offset sum. | |
| for (int t=rows-1; t>=0; --t) { | |
| auto src = head.data() + t*2948 + offset; | |
| for (int i=0; i<bins; ++i) { | |
| float mag = std::exp(std::min(src[i], std::log(100.f))); | |
| spectrum[i] = {mag*std::cos(src[bins+i]), mag*std::sin(src[bins+i])}; | |
| } | |
| pocketfft::c2r<float>({size_t(fft)}, {sizeof(std::complex<float>)}, {sizeof(float)}, 0, | |
| false, spectrum.data(), block.data(), 1.f); | |
| for (int i=0; i<fft; ++i) { | |
| sum[t*hop+i] += (block[i]*(1.f/fft))*window[i]; | |
| env[t*hop+i] += window[i]*window[i]; | |
| } | |
| } | |
| Floats audio(rows*hop); | |
| for (size_t i=0; i<audio.size(); ++i) { | |
| size_t j = i + fft/2; | |
| audio[i] = sum[j] / (env[j] > 1e-11f ? env[j] : 1.f); | |
| } | |
| return audio; | |
| } | |
| Floats decode_audio(const Floats& head, int frames, const fs::path& shared) { | |
| auto a = branch_audio(head, frames, 736, 0, read_file<float>(shared/"hann736.f32",736)); | |
| auto b = branch_audio(head, frames, 2208, 738, read_file<float>(shared/"hann2208.f32",2208)); | |
| auto mixer = read_file<float>(shared/"mixer.f32",254); | |
| auto kernel = read_file<float>(shared/"resample.f32",735*770); | |
| Floats mix(17 + a.size() + 17 + 736); | |
| for (int ch=0; ch<2; ++ch) { | |
| Floats padded(a.size()+126); | |
| auto& x = ch ? b : a; | |
| std::copy(x.begin(), x.end(), padded.begin()+63); | |
| for (size_t j=0; j<x.size(); ++j) { | |
| float v=0; | |
| for (int k=0; k<127; ++k) v += padded[j+k]*mixer[ch*127+k]; | |
| mix[17+j] += v; | |
| } | |
| } | |
| Floats wave(frames*2940); | |
| const float gain=std::pow(10., -3./20.), knee=std::pow(10., -1./20.); | |
| for (size_t i=0; i<wave.size(); ++i) { | |
| const float* segment=mix.data()+(i/735)*736; | |
| const float* coeff=kernel.data()+(i%735)*770; | |
| float sample=0; | |
| for (int k=0; k<770; ++k) sample += segment[k]*coeff[k]; | |
| sample *= gain; | |
| if (std::abs(sample)>knee) | |
| sample=std::copysign(knee+(1-knee)*std::tanh((std::abs(sample)-knee)/(1-knee)),sample); | |
| require(std::isfinite(sample), "nonfinite waveform"); | |
| wave[i]=sample; | |
| } | |
| return wave; | |
| } | |
| void save_audio(const fs::path& dest, const Floats& wave) { | |
| write_file(dest/"waveform.f32",wave); | |
| std::ofstream f(dest/"waveform.wav",std::ios::binary); | |
| auto u16=[&](uint16_t v){f.write(reinterpret_cast<const char*>(&v),2);}; | |
| auto u32=[&](uint32_t v){f.write(reinterpret_cast<const char*>(&v),4);}; | |
| f.write("RIFF",4); u32(36+wave.size()*2); f.write("WAVEfmt ",8); u32(16); | |
| u16(1); u16(1); u32(44100); u32(88200); u16(2); u16(16); | |
| f.write("data",4); u32(wave.size()*2); | |
| for (float x:wave) u16(static_cast<int16_t>(std::nearbyint(std::clamp(x,-1.f,1.f)*32767.f))); | |
| f.close(); | |
| require(bool(f),"write waveform.wav"); | |
| } | |