Overview
The Advanced Local Audio Analyzer represents an educational instrument designed to explore natural language sentiment classification joined with real-time digital signal processing of acoustic voice features. Operating as a self-contained, client-side browser simulator, this system maps auditory elements to emotional matrices entirely within the local computational bounds of the user's terminal, ensuring private, offline-capable analysis.
Human vocal communication consists of two distinct layers of semantic structure: the lexical tier (the chosen words and linguistic syntaxes) and the acoustic prosodic tier (the non-verbal vocal expressions such as pitch variations, intensity, rhythm, and spectral dynamics). This system maps both tiers simultaneously using a rule-based Natural Language Processing (NLP) framework combined with a real-time Fast Fourier Transform (FFT) signal analysis pipeline.
Mathematically, the composite emotional state vector $\mathbf{E}_{comp}$ is formulated as a linear combination of the text-derived emotional indices $\mathbf{E}_{txt}$ and acoustic features $\mathbf{E}_{ac}$ weighted dynamically based on interactive laboratory sliders:
$$ \mathbf{E}_{comp} = W_{txt} \cdot \mathbf{E}_{txt} + W_{ac} \cdot \mathbf{E}_{ac} $$
Where $W_{txt}$ and $W_{ac}$ represent the computational weights of the textual and acoustic engines, satisfying the physical balance relation $W_{txt} + W_{ac} = 1.0$. The derived emotional matrix maps onto a six-dimensional hyperspace defining primary affective states:
$$\mathbf{E} = \{ \text{joy}, \text{sadness}, \text{anger}, \text{fear}, \text{surprise}, \text{disgust} \}$$
Technical Details
This application uses vanilla Javascript, the HTML5 Canvas API, the Web Audio API, and the Web Speech API. The following computational mechanics govern the analyzer:
Browser Speech Recognition Compatibility (Firefox vs Chromium)
The Web Speech API standard (`SpeechRecognition` interface) is supported natively out of the box in Google Chrome, Microsoft Edge, Opera, and Apple Safari. However, in **Mozilla Firefox**, the speech recognition engine is disabled by default in standard public builds. Firefox requires manual flag activation by entering about:config and toggling media.webspeech.recognition.enable to true.
To ensure uninterrupted usability across all browsers (including stock Firefox builds), this simulator decouples text-based NLP classification from real-time microphone capture:
- Full NLP Lexical Classification: Manual text entry, preset phrase simulation, n-gram parsing, intensifier amplification, negation inversion, and sentiment scoring operate 100% locally in Javascript without external API dependencies.
- Acoustic DSP Oscilloscope: The Web Audio API FFT spectrum analyzer, pitch autocorrelation tracker, and RMS energy meter function universally across Firefox, Safari, Chrome, and Edge without restriction.
Acoustic Feature Processing via Web Audio API
When voice capture is active, a MediaStreamAudioSourceNode feeds raw digital samples into a high-resolution AnalyserNode. Frequency domain data is gathered using a $2048$-point Fast Fourier Transform (FFT).
Vocal loudness is calculated using the Root Mean Square (RMS) amplitude of the time-domain buffer vector $x$:
$$ V_{rms} = \sqrt{\frac{1}{N}\sum_{n=0}^{N-1} x[n]^2} $$
To calculate pitch, the system implements a Zero-Crossing Rate (ZCR) mathematical module paired with autocorrelation. While simple peak FFT tracking is prone to error due to vocal harmonics, autocorrelation determines pitch by searching for self-similarity at varying window sample offsets ($k$):
$$ R_x[k] = \sum_{n=0}^{W-1} x[n] \cdot x[n + k] $$
By tracking the first significant maximum correlation peak outside of zero lag, the system extracts the fundamental vocal frequency $f_0$. Higher pitches and fluctuating rates of change correspond to shock, excitement, or aggression, while flat, soft signals map to sadness or neutral modes.
Natural Language Sentiment and N-Gram Engine
The lexicon matching structure processes text strings iteratively using a descending n-gram matching hierarchy (Trigrams $\rightarrow$ Bigrams $\rightarrow$ Unigrams). The system implements an Intensifier Multiplier $M$ and Negation Inverter $N$. When a matched token $w_i$ is preceded by an intensifier (e.g., "extremely", $M_i = 1.8$), sentiment is amplified. If preceded by a negator (e.g., "not", $N_i = -1.0$), polarity reverses:
$$ S_i = s(w_i) \cdot M_i \cdot N_i $$
Low-Pass Interpolation Filter
Target sentiment and emotional vectors are filtered using linear interpolation (Lerp):
$$ Y_t = (1 - \alpha) \cdot Y_{t-1} + \alpha \cdot X_t $$
Where $X_t$ is raw engine output, $Y_{t-1}$ is the previous frame coordinate, and $\alpha$ is the user-tuned Temporal Smoothing Factor.