-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FeatureExtractor, validate_audio_inputs } from '../../base/feature_extraction_utils.js'; | ||
import { Tensor } from '../../utils/tensor.js'; | ||
|
||
|
||
export class MoonshineFeatureExtractor extends FeatureExtractor { | ||
/** | ||
* Asynchronously extracts input values from a given audio using the provided configuration. | ||
* @param {Float32Array|Float64Array} audio The audio data as a Float32Array/Float64Array. | ||
* @returns {Promise<{ input_values: Tensor; }>} The extracted input values. | ||
*/ | ||
async _call(audio) { | ||
validate_audio_inputs(audio, 'MoonshineFeatureExtractor'); | ||
|
||
if (audio instanceof Float64Array) { | ||
audio = new Float32Array(audio); | ||
} | ||
|
||
const shape = [ | ||
1, /* batch_size */ | ||
audio.length, /* num_samples */ | ||
]; | ||
return { | ||
input_values: new Tensor('float32', audio, shape), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { AutoFeatureExtractor } from "../auto/feature_extraction_auto.js" | ||
import { AutoTokenizer } from "../../tokenizers.js" | ||
import { Processor } from "../../base/processing_utils.js" | ||
|
||
/** | ||
* Represents a MoonshineProcessor that extracts features from an audio input. | ||
*/ | ||
export class MoonshineProcessor extends Processor { | ||
static tokenizer_class = AutoTokenizer | ||
static feature_extractor_class = AutoFeatureExtractor | ||
|
||
/** | ||
* Calls the feature_extractor function with the given audio input. | ||
* @param {any} audio The audio input to extract features from. | ||
* @returns {Promise<any>} A Promise that resolves with the extracted features. | ||
*/ | ||
async _call(audio) { | ||
return await this.feature_extractor(audio); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters