Automation foundation model for tiny devices: 2-bit, 8-29 MB, tool calls, ASR, structured extraction and embeddings on phones, wearables, smart homes, robots, cars and microcontrollers.
fix: update version to 3.2.0 and improve audio length handling in Whistle
HenryNdubuaku24d5765dc2d2
diff --git a/README.md b/README.mdindex 1c4bab7..db4b990 100644--- a/README.md+++ b/README.md@@ -48,7 +48,7 @@ Every turn returns one JSON object with `function_calls`, the model's `reasoning-Whistle is our speech-to-text model, one 16.9 MB file on the CPU: 16 kHz mono audio, up to 30 seconds in one pass, in English, German, French, Spanish, Italian, Dutch and Polish. It shares Needle's `.cact` container, its quantisation and its C++ engine, so the two are one runtime, and its decoder is laddered the same way, with `--audio-depth N` running the N-layer rung of the same weights.+Whistle is our speech-to-text model, one 16.9 MB file on the CPU: 16 kHz mono audio of any length, one pass up to 30 seconds and windowed beyond it, in English, German, French, Spanish, Italian, Dutch and Polish. It shares Needle's `.cact` container, its quantisation and its C++ engine, so the two are one runtime, and its decoder is laddered the same way, with `--audio-depth N` running the N-layer rung of the same weights.```pythonimport needlediff --git a/needle/__init__.py b/needle/__init__.pyindex 5993c45..b940c08 100644--- a/needle/__init__.py+++ b/needle/__init__.py@@ -13,7 +13,7 @@ from ._telemetry import track as _trackfrom ._worker import FineTuneWorkerfrom .agent.whistle import Whistle, stream, transcribe-__version__ = "3.1.0"+__version__ = "3.2.0"__all__ = ["Needle", "Whistle", "ExtractionValidationError", "tool", "Field", "extract","transcribe", "stream", "__version__"]diff --git a/needle/agent/fetch.py b/needle/agent/fetch.pyindex 33d3491..c4627b3 100644--- a/needle/agent/fetch.py+++ b/needle/agent/fetch.py@@ -13,7 +13,7 @@ ENGINE_REPOS = {}ENGINE_VERSIONS = {2: "2.0.4",- 3: "3.2.0",+ 3: "3.3.0",WHISTLE: "2.0.0",}diff --git a/needle/agent/whistle.py b/needle/agent/whistle.pyindex 109d883..bd189f9 100644--- a/needle/agent/whistle.py+++ b/needle/agent/whistle.py@@ -98,7 +98,7 @@ def _samples(audio):class Whistle:"""Speech-to-text in English, German, French, Spanish, Italian, Dutch and Polish.- Audio is a WAV file path or 16 kHz mono float samples in [-1, 1], at most 30 s.+ Audio is a WAV file path or 16 kHz mono float samples in [-1, 1], of any length.One model is loaded per process; it is not thread-safe."""@@ -181,7 +181,7 @@ def _shared_model(weights):def transcribe(audio, language=None, keywords=None, word_timestamps=False, weights=None) -> dict:"""Speech to text, on the model this process already has loaded.- audio is a WAV file path or 16 kHz mono float samples in [-1, 1], at most 30 s.+ audio is a WAV file path or 16 kHz mono float samples in [-1, 1], of any length.Returns {"text", "language", "ttft_ms", "decode_tps"}, plus "words" with start,end and probability when word_timestamps is set. language is one of LANGUAGES,or None to detect it; keywords are words or phrases for keyword biasing.@@ -220,7 +220,6 @@ COMPARE_INSTALL = 'pip install "cactus-needle[mic,compare]"'CLEAR_ABOVE = "\x1b[1A\x1b[2K"DIM = "\x1b[90m"PLAIN = "\x1b[0m"-LIMIT_SECONDS = 30def audio_path(rest):@@ -257,10 +256,7 @@ def record():except sounddevice.PortAudioError as error:raise RuntimeError(f"no microphone: {error}") from Noneprint(CLEAR_ABOVE, end="", flush=True)- heard = numpy.concatenate(chunks)[:, 0] if chunks else numpy.zeros(0, numpy.float32)- audio = heard[:LIMIT_SECONDS * rate]- if len(audio) < len(heard):- print(f" keeping the first {LIMIT_SECONDS} s")+ audio = numpy.concatenate(chunks)[:, 0] if chunks else numpy.zeros(0, numpy.float32)return audio if rate == SAMPLE_RATE else soxr.resample(audio, rate, SAMPLE_RATE, quality="HQ")diff --git a/pyproject.toml b/pyproject.tomlindex 82a4dec..97ab73e 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -1,6 +1,6 @@[project]name = "cactus-needle"-version = "3.1.0"+version = "3.2.0"description = "A 14MB foundation tool-calling model for tiny devices: inference, LoRA finetuning, and build."requires-python = ">=3.9"readme = "README.md"diff --git a/tests/test_whistle.py b/tests/test_whistle.pyindex 1b85df7..78bb467 100644--- a/tests/test_whistle.py+++ b/tests/test_whistle.py@@ -206,14 +206,16 @@ def test_transcribe_returns_text_language_and_timed_words(tmp_path):@requires_whistle-def test_embed_and_the_30_second_limit():+def test_embed_keeps_its_window_and_transcribe_takes_long_audio():from needle import Whistlewhistle = Whistle()embedding = whistle.embed(_tone(1))assert len(embedding) > 0 and all(isinstance(v, float) for v in embedding[:8])with pytest.raises(RuntimeError, match="30 s"):- whistle.transcribe([0.0] * (30 * 16000 + 1))+ whistle.embed([0.0] * (30 * 16000 + 1))+ long = whistle.transcribe([0.0] * (31 * 16000), word_timestamps=True)+ assert long["text"] == "" and long["language"] == "" and long["words"] == []@requires_whistle@@ -265,7 +267,7 @@ class _Microphone:return Stream()-def test_record_resamples_the_microphone_to_16_khz_and_keeps_30_s(monkeypatch, capsys):+def test_record_resamples_the_microphone_to_16_khz_and_keeps_everything(monkeypatch, capsys):numpy = pytest.importorskip("numpy")pytest.importorskip("soxr")from needle.agent.whistle import record@@ -278,8 +280,7 @@ def test_record_resamples_the_microphone_to_16_khz_and_keeps_30_s(monkeypatch, cassert audio.dtype == numpy.float32 and len(audio) == 16000 and abs(float(audio[8000]) - 0.25) < 0.01assert "recording, Enter to stop" in capsys.readouterr().outmonkeypatch.setitem(sys.modules, "sounddevice", _Microphone(16000, 31))- assert len(record()) == 30 * 16000- assert "keeping the first 30 s" in capsys.readouterr().out+ assert len(record()) == 31 * 16000def test_record_says_what_is_missing(monkeypatch):