<p>After more investigation, turns out the CREPE model itself supports up to ~1997Hz (seen in code) or 1975.5 Hz (seen in paper)</p>
<p>The paper about CREPE:
<a href="https://arxiv.org/abs/1802.06182" rel="nofollow noreferrer">https://arxiv.org/abs/1802.06182</a></p>
<p>States:</p>
<blockquote>
<p>The 360 pitch values are denoted as c1, c2..., 360 are selected so that they cover six octaves with 20-cent intervals between C1 and B7, corresponding to 32.70 Hz and 1975.5 Hz</p>
</blockquote>
<p>The <a href="https://marl.github.io/crepe/crepe.js" rel="nofollow noreferrer">JS implementation</a> has this mapping which maps the 360 intervals to 0 - 1997Hz range:</p>
<p><code>const cent_mapping = tf.add(tf.linspace(0, 7180, 360), tf.tensor(1997.3794084376191))</code></p>
<p>This means, short of retraining the model I'm probably out of luck at using it for now.</p>
<hr />
<p>Edit:</p>
<p>After a good nights sleep I found a simple solution which works for my simple application.</p>
<p>In it's essence, it is to resample my audio buffer so it has 2 times lower pitch. CREPE than detects a pitch of 440Hz as 220Hz, and I just need to multiply it by 2.</p>
<p>The result is still more consistently correct than YIN algorithm for my real time, noisy application.</p>
In ml5 pitch detection using crepe model, how to detect pitch above ±2kHz
<p>I'm successfully using pitch detection features of ml5:</p>
<ul>
<li>tutorial: <a href="https://ml5js.org/reference/api-PitchDetection/" rel="nofollow noreferrer">https://ml5js.org/reference/api-PitchDetection/</a></li>
<li>model: <a href="https://cdn.jsdelivr.net/gh/ml5js/ml5-data-and-models/models/pitch-detection/crepe/" rel="nofollow noreferrer">https://cdn.jsdelivr.net/gh/ml5js/ml5-data-and-models/models/pitch-detection/crepe/</a></li>
</ul>
<h2>The issue:</h2>
<p>No pitch above ±2000Hz is detected. I tried multiple devices and checked that the sounds are visible on sonograms so it's does not seem to be a mic issue.</p>
<p>I assumed it may be a result of sampling rate limitations / resampling done by the library, as the Nyquist frequency (max &quot;recordable&quot; frequency) is that of half of the sampling rate.</p>
<p>I hosted the ml5 sources localy and tried modifying the <a href="https://github.com/ml5js/ml5-library/tree/main/src/PitchDetection" rel="nofollow noreferrer">PitchDetection class</a></p>
<p>There I see the sampling rate seems to be resampled to 1024Hz for performance reasons. This does not sound right though as if I'm not mistaken, this would only allow detection of frequencies up to 512hz. I am definitely missing something (or a lot).</p>
<p>I tried fiddling with the rates, but increasing it to, say 2048 causes an error:
<code>Error when checking : expected crepe_input to have shape [null,1024] but got array with shape [1,2048].</code></p>
<h2>My question is:</h2>
<p>Is there something in ml5 <a href="https://github.com/ml5js/ml5-library/tree/main/src/PitchDetection" rel="nofollow noreferrer">PitchDetection class</a> I can modify, configure (perhaps a different model) to detect frequencies higher than 2000Hz using crepe model?</p>