Skip to content

Commit 1823b07

Browse files
committed
rename Crepe as pitchDetection
1 parent 03fc3e1 commit 1823b07

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/Crepe/index.js renamed to src/PitchDetection/index.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
import * as tf from '@tensorflow/tfjs';
1313

14-
class Crepe {
15-
constructor(audioContext, stream) {
14+
class PitchDetection {
15+
constructor(modelName, audioContext, stream) {
16+
this.modelName = modelName;
1617
this.audioContext = audioContext;
1718
this.stream = stream;
1819
this.loadModel();
@@ -76,7 +77,7 @@ class Crepe {
7677
processMicrophoneBuffer(event) {
7778
this.results = {};
7879
const centMapping = tf.add(tf.linspace(0, 7180, 360), tf.tensor(1997.3794084376191));
79-
Crepe.resample(event.inputBuffer, (resampled) => {
80+
PitchDetection.resample(event.inputBuffer, (resampled) => {
8081
tf.tidy(() => {
8182
this.running = true;
8283
const frame = tf.tensor(resampled.slice(0, 1024));
@@ -111,6 +112,18 @@ class Crepe {
111112
}
112113
}
113114

114-
const crepe = (context, stream) => new Crepe(context, stream);
115+
const pitchDetection = (modelName, context, stream) => {
116+
let model;
117+
if (typeof modelName === 'string') {
118+
model = modelName.toLowerCase();
119+
} else {
120+
throw new Error('Please specify a model to use. E.g: "Crepe"');
121+
}
122+
123+
if (model === 'crepe') {
124+
return new PitchDetection(model, context, stream);
125+
}
126+
throw new Error(`${model} is not a valid model to use in pitchDetection()`);
127+
};
115128

116-
export default crepe;
129+
export default pitchDetection;

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// https://opensource.org/licenses/MIT
55

66
import * as tf from '@tensorflow/tfjs';
7-
import Crepe from './Crepe/';
7+
import pitchDetection from './PitchDetection/';
88
import imageClassifier from './ImageClassifier/';
99
import featureExtractor from './FeatureExtractor/';
1010
import Word2Vec from './Word2vec/';
@@ -17,7 +17,7 @@ import LSTMGenerator from './LSTM/';
1717
module.exports = {
1818
imageClassifier,
1919
featureExtractor,
20-
Crepe,
20+
pitchDetection,
2121
YOLO,
2222
Word2Vec,
2323
StyleTransfer,

0 commit comments

Comments
 (0)