inaSpeechSegmenter developer on retainer: timestamps are wall-clock seconds — developer uses segmenter’s 16 000 Hz internal rate to convert to sample indices in 44 100 Hz files — segments 2.75× too short at wrong positions — broadcast transcripts incoherent — 10 000 recordings per month — 3 weeks — inaSpeechSegmenter developer on monthly retainer

inaSpeechSegmenter 0.7.7 • Python 3.9 • soundfile 0.12.1; Segmenter()(path) returns (label, start_time, end_time) in wall-clock seconds; developer uses SAMPLE_RATE = 16000 (segmenter’s internal rate); for speech at 20.0–30.0 s in 44100 Hz file: extracts samples 320000–480000 (7.26–10.88 s, 3.63 s) instead of 882000–1323000 (20.0–30.0 s, 10.0 s) • Northfield Inaspeechsegmenter Ltd. (broadcast monitoring; 200 radio stations; 10,000 recordings/month; speech-to-text transcripts incoherent; 3 weeks; fix: soundfile.info(path).samplerate; 2.0h retainer engagement)

Northfield Inaspeechsegmenter Ltd. built an automated broadcast monitoring service that ran inaSpeechSegmenter 0.7.7 on recordings from 200 radio stations — 10,000 WAV files per month — to extract speech segments and submit them to a speech-to-text API for transcript generation. The service classified each recording into speech, music, and noise regions, extracted the speech segments as audio arrays, and fed them to the transcription pipeline. Radio station clients reported that after the first month of operation, all produced transcripts were incoherent: words from the wrong time ranges, sentences that bore no relation to the labeled speech intervals, and transcripts that matched the music or noise regions instead of the speech content.

inaSpeechSegmenter 0.7.7 Segmenter()(audio_path) returns a list of tuples (label, start_time, end_time) where label is one of 'speech', 'music', 'noEnergy', 'male', or 'female', and start_time and end_time are Python floats expressing time in wall-clock seconds. The Segmenter internally resamples all input audio to 16 000 Hz before running CNN inference; this 16 000 Hz figure appears prominently in the inaSpeechSegmenter documentation and source code. The developer read this and concluded that the returned timestamps must refer to sample positions in a 16 000 Hz signal. The developer set SAMPLE_RATE = 16000 globally and computed sample indices as int(start_time * SAMPLE_RATE). The actual WAV files from radio stations were recorded at 44 100 Hz. When the developer loaded a file with soundfile.read(path) (which returns the audio at the file’s native sample rate — 44 100 Hz, 2 646 000 samples for a 60-second recording) and extracted a speech segment labeled ('speech', 20.0, 30.0), the computed indices were start = int(20.0 × 16000) = 320000 and end = int(30.0 × 16000) = 480000. The correct indices were 882000 and 1323000. The extracted array audio[320000:480000] was 160 000 samples long, representing 160000 ÷ 44100 = 3.63 seconds of audio starting at 320000 ÷ 44100 = 7.26 seconds — not the labeled speech region at 20.0–30.0 seconds.

The annotated buggy and fixed segment extraction code, with sample rate validation and duration assertion:

# Northfield Inaspeechsegmenter Ltd. — inaSpeechSegmenter 0.7.7 sample rate fix
# inaSpeechSegmenter 0.7.7; Python 3.9; soundfile 0.12.1
# Broadcast monitoring; 200 stations; 10,000 WAV recordings/month at 44100 Hz
#
# Problem: Segmenter()(path) returns timestamps in wall-clock SECONDS
#          Segmenter resamples internally to 16000 Hz — but output times are seconds
#          Developer hardcoded SAMPLE_RATE = 16000 from documentation
#          For speech (20.0, 30.0) on a 44100 Hz file:
#            int(20.0 * 16000) = 320000, int(30.0 * 16000) = 480000
#            audio[320000:480000] = 160000 samples = 3.63 s starting at 7.26 s
#          Correct:
#            int(20.0 * 44100) = 882000, int(30.0 * 44100) = 1323000
#            audio[882000:1323000] = 441000 samples = 10.0 s starting at 20.0 s
#          No exception; speech-to-text gets wrong audio; transcripts incoherent
# Fix:     Use soundfile.info(path).samplerate — the actual file sample rate

import numpy as np
import soundfile as sf
from inaSpeechSegmenter import Segmenter

segmenter = Segmenter()   # Initialize once; reuse across all files


# ── BUGGY segment extraction ──────────────────────────────────────────────────

SAMPLE_RATE = 16000  # BUG: inaSpeechSegmenter's internal rate, not the file's rate

def extract_speech_segments_buggy(audio_path: str) -> list[np.ndarray]:
    """Extract speech segments — BUGGY: uses segmenter internal rate not file rate."""
    segments_result = segmenter(audio_path)
    audio, _ = sf.read(audio_path)  # actual sr=44100, but _ discarded

    speech_clips = []
    for label, start_time, end_time in segments_result:
        if label not in ('speech', 'male', 'female'):
            continue
        # BUG: timestamps are wall-clock seconds; must use FILE sample rate
        # Using 16000 instead of 44100: start is 2.75× too early, duration 2.75× too short
        start_sample = int(start_time * SAMPLE_RATE)   # int(20.0 * 16000) = 320000
        end_sample   = int(end_time   * SAMPLE_RATE)   # int(30.0 * 16000) = 480000
        speech_clips.append(audio[start_sample:end_sample])  # wrong segment
    return speech_clips


# ── FIXED segment extraction ──────────────────────────────────────────────────

def extract_speech_segments(audio_path: str) -> list[np.ndarray]:
    """Extract speech segments — FIXED: uses actual file sample rate."""
    segments_result = segmenter(audio_path)
    audio, file_sr = sf.read(audio_path, dtype='float32')

    # inaSpeechSegmenter's internal 16000 Hz rate is irrelevant here.
    # Timestamps are wall-clock seconds; use FILE sample rate for index conversion.
    if file_sr == 16000:
        # Coincidental match — still validate explicitly
        pass
    elif file_sr not in (44100, 48000, 22050, 8000):
        raise ValueError(
            f"Unexpected file sample rate {file_sr} Hz in {audio_path}. "
            "Verify inaSpeechSegmenter supports this rate and check timestamp units."
        )

    speech_clips = []
    for label, start_time, end_time in segments_result:
        if label not in ('speech', 'male', 'female'):
            continue

        start_sample = int(start_time * file_sr)
        end_sample   = int(end_time   * file_sr)

        # Clamp to valid array bounds (floating-point rounding at file end)
        start_sample = max(0, start_sample)
        end_sample   = min(len(audio), end_sample)

        segment = audio[start_sample:end_sample]
        expected_samples = int((end_time - start_time) * file_sr)

        # Assert duration within 1% — catches sample rate mismatch regressions
        if abs(len(segment) - expected_samples) > max(1, int(expected_samples * 0.01)):
            raise RuntimeError(
                f"Extracted segment length {len(segment)} samples, "
                f"expected ~{expected_samples} samples for "
                f"{end_time - start_time:.3f}s at {file_sr} Hz. "
                "Possible sample rate mismatch — verify file_sr is the actual "
                "sample rate of the audio array, not inaSpeechSegmenter's "
                "internal 16000 Hz processing rate."
            )

        speech_clips.append(segment)
    return speech_clips


def startup_extraction_test() -> None:
    """Verify sample rate conversion at service startup using a known test file."""
    import tempfile, struct, math, wave, os
    # Create a known 10-second 440 Hz sine at 44100 Hz with speech label at 2.0-5.0 s
    n_samples = 10 * 44100
    with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as tmp:
        test_path = tmp.name
    with wave.open(test_path, 'w') as wf:
        wf.setnchannels(1)
        wf.setsampwidth(2)
        wf.setframerate(44100)
        samples = [int(32767 * math.sin(2 * math.pi * 440 * i / 44100))
                   for i in range(n_samples)]
        wf.writeframes(struct.pack(f'<{n_samples}h', *samples))

    audio, file_sr = sf.read(test_path, dtype='float32')
    os.unlink(test_path)

    expected_sr = 44100
    if file_sr != expected_sr:
        raise RuntimeError(
            f"Test file sample rate {file_sr}, expected {expected_sr}. "
            "soundfile.read() may be resampling."
        )

    # Simulate a 3-second speech segment at t=2.0
    start_time, end_time = 2.0, 5.0
    correct_start = int(start_time * file_sr)   # 88200
    correct_end   = int(end_time   * file_sr)   # 220500
    expected_len  = correct_end - correct_start  # 132300

    wrong_start = int(start_time * 16000)   # 32000
    wrong_end   = int(end_time   * 16000)   # 80000
    wrong_len   = wrong_end - wrong_start    # 48000

    if wrong_len == expected_len:
        raise RuntimeError("Test file is 16000 Hz — cannot distinguish correct from buggy path.")

    segment = audio[correct_start:correct_end]
    if len(segment) != expected_len:
        raise RuntimeError(
            f"Startup test: extracted {len(segment)} samples, expected {expected_len}. "
            "Check sample rate — SAMPLE_RATE=16000 produces {wrong_len} samples."
        )

How the segmenter’s documented 16 000 Hz internal processing rate, wall-clock second timestamps that look like sample indices, and silent array slicing combine to produce three weeks of incoherent transcripts — and the correct soundfile.info(path).samplerate pattern for inaSpeechSegmenter segment extraction

The core failure combines three independent factors: inaSpeechSegmenter’s internal 16 000 Hz processing rate is prominently documented because it determines the minimum useful input sample rate and affects processing latency — developers naturally associate this figure with the timestamp units even though timestamps are always wall-clock seconds; NumPy array slicing with out-of-range integer indices silently returns shorter arrays rather than raising an IndexError (the slice audio[320000:480000] on a 2 646 000-sample array returns exactly 160 000 samples with no error); and the speech-to-text API accepts any audio array of valid dtype and length, returning a transcript of whatever audio it receives without indicating that the content is from the wrong time range. The correct conversion reads the file’s actual sample rate on every call: audio, file_sr = sf.read(path), then start_sample = int(start_time * file_sr). The rule is: inaSpeechSegmenter’s 16 000 Hz internal rate is an implementation detail that governs how the model processes audio; it has no relationship to the timestamps in the returned tuples, which always express time in seconds. Any pipeline that extracts segments from the original audio file must use the original file’s sample rate for index conversion, not the segmenter’s internal rate. The recovery required re-running segmentation and extraction on all 10,000 recordings with the corrected sample rate and resubmitting to the speech-to-text API; the retainer engagement was 2.0h: 0.5h triage (manual comparison of extracted segment content vs expected; timestamps correct in segmenter output; duration mismatch: 3.63s not 10.0s); 0.5h root cause (SAMPLE_RATE=16000 hardcoded; actual file rate 44100; factor 44100/16000=2.75×); 0.5h fix (soundfile.info(path).samplerate per file; segment duration assertion; startup integration test); 0.5h validation (100-recording test; segment durations correct; speech-to-text transcripts coherent; 2.0h total). Hours logged to HourTab with per-session breakdown.

Related retainer posts


Track retainer hours without a client portal

HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.

See pricing →