Skip to content

Commit

Permalink
webvp wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 committed Aug 18, 2022
1 parent 8ae0af5 commit 448e9b5
Show file tree
Hide file tree
Showing 23 changed files with 1,506 additions and 1,129 deletions.
25 changes: 0 additions & 25 deletions demo/vu_worker_engine.js

This file was deleted.

20 changes: 11 additions & 9 deletions package/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 12,10 @@ module.exports = {
ecmaVersion: 2018
},

ignorePatterns: ['**/*.js', 'node_modules', 'dist'],
overrides: [
{
files: ['**/*.ts', '**/*.tsx'],
files: ['src/**/*.ts'],
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/no-parameter-properties': 2,
Expand All @@ -24,8 25,9 @@ module.exports = {
'@typescript-eslint/no-use-before-define': 2,
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/no-empty-interface': 2,
'@typescript-eslint/explicit-function-return-type': 2,
'@typescript-eslint/ban-ts-ignore': 0,
'@typescript-eslint/explicit-function-return-type': 1,
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/no-empty-function': [2, { "allow": ["constructors"] }],
'@typescript-eslint/no-inferrable-types': [
2,
{
Expand All @@ -43,11 45,11 @@ module.exports = {
//=========================================================================

// disallow trailing commas in object literals
'comma-dangle': [2, 'always-multiline'], //TODO: need discussion
'comma-dangle': [0, 'always-multiline'], //TODO: need discussion
// disallow assignment in conditional expressions
'no-cond-assign': [2, 'always'],
// disallow use of console
'no-console': 0,
'no-console': 1,
// disallow use of constant expressions in conditions
'no-constant-condition': [2, { checkLoops: false }],
// disallow control characters in regular expressions
Expand Down Expand Up @@ -96,7 98,7 @@ module.exports = {
'use-isnan': 2,
// ensure JSDoc comments are valid
'valid-jsdoc': [
2,
0,
{
requireReturn: false,
requireReturnDescription: false
Expand All @@ -121,7 123,7 @@ module.exports = {
// require default case in switch statements
'default-case': 2,
// encourages use of dot notation whenever possible
'dot-notation': [0, { allowKeywords: true }],
'dot-notation': [2, { allowKeywords: true }],
// enforces consistent newlines before or after dots
'dot-location': [2, 'property'],
// require the use of === and !==
Expand Down Expand Up @@ -257,7 259,7 @@ module.exports = {
// disallow declaration of variables that are not used in the code
'no-unused-vars': [1, { vars: 'local', args: 'after-used' }],
// disallow use of variables before they are defined
'no-use-before-define': 2,
'no-use-before-define': 0,

//=========================================================================
//==================== Node.js ============================================
Expand Down Expand Up @@ -383,7 385,7 @@ module.exports = {
// require quotes around object literal property names
'quote-props': 0,
// specify whether double or single quotes should be used
quotes: [1, 'single', 'avoid-escape'],
quotes: 0,
// Require JSDoc comment
'require-jsdoc': 0,
// enforce spacing before and after semicolons
Expand Down
14 changes: 14 additions & 0 deletions package/module.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,14 @@
declare module "*.wasm" {
const content: string;
export default content;
}

declare module "*.js" {
const content: string;
export default content;
}

declare module 'web-worker:*' {
const WorkerFactory: new () => Worker;
export default WorkerFactory;
}
32 changes: 17 additions & 15 deletions package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
{
"name": "@picovoice/web-voice-processor",
"version": "2.2.3",
"version": "2.3.0",
"description": "Real-time audio processing for voice, in web browsers",
"entry": "src/index.ts",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -44,25 44,27 @@
},
"homepage": "https://github.com/Picovoice/web-voice-processor#readme",
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/core": "^7.18.10",
"@babel/plugin-transform-runtime": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"@babel/runtime": "^7.18.3",
"@rollup/plugin-babel": "^5.2.3",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.1.1",
"@typescript-eslint/eslint-plugin": "^4.15.0",
"@typescript-eslint/parser": "^4.15.0",
"@free-side/audioworklet-polyfill": "^1.1.3-beta.4",
"@picovoice/web-utils": "=1.2.3",
"@rollup/plugin-babel": "^5.3.1",
"@rollup/plugin-commonjs": "^18.1.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/pluginutils": "^4.2.1",
"@typescript-eslint/eslint-plugin": "^5.19.0",
"@typescript-eslint/parser": "^5.19.0",
"cross-env": "^7.0.3",
"eslint": "^7.19.0",
"eslint": "^8.13.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"rollup": "^2.38.5",
"rollup-plugin-sourcemaps": "^0.6.3",
"prettier": "^2.6.2",
"rollup": "^2.70.1",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-typescript2": "^0.29.0",
"rollup-plugin-web-worker-loader": "^1.6.0",
"tslib": "^2.1.0",
"typescript": "^4.1.5"
"rollup-plugin-typescript2": "^0.31.2",
"rollup-plugin-web-worker-loader": "^1.6.1",
"tslib": "^2.3.1",
"typescript": "^4.6.3"
}
}
29 changes: 21 additions & 8 deletions package/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 3,61 @@ const path = require('path');
const { nodeResolve } = require('@rollup/plugin-node-resolve');
const commonjs = require('@rollup/plugin-commonjs');
const typescript = require('rollup-plugin-typescript2');
const sourceMaps = require('rollup-plugin-sourcemaps');
const workerLoader = require('rollup-plugin-web-worker-loader');
const pkg = require('./package.json');
const { babel } = require('@rollup/plugin-babel');
const terser = require('rollup-plugin-terser').terser;
const { DEFAULT_EXTENSIONS } = require('@babel/core');
const { base64 } = require('@picovoice/web-utils/plugins');

const extensions = [...DEFAULT_EXTENSIONS, '.ts'];

console.log(process.env.TARGET);
console.log(extensions);

function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() string.slice(1);
}

const iifeBundleName = pkg.name
.split('@picovoice/')[1]
.split('-')
.map(word => capitalizeFirstLetter(word))
.join('');
console.log(iifeBundleName);

export default {
input: [path.resolve(__dirname, pkg.entry)],
output: [
{
file: path.resolve(__dirname, pkg.module),
format: 'esm',
sourcemap: true,
sourcemap: false,
},
{
file: path.resolve(__dirname, 'dist', 'esm', 'index.min.js'),
format: 'esm',
sourcemap: true,
sourcemap: false,
plugins: [terser()],
},
{
file: path.resolve(__dirname, pkg.iife),
format: 'iife',
name: 'WebVoiceProcessor',
sourcemap: true,
name: iifeBundleName,
sourcemap: false,
},
{
file: path.resolve(__dirname, 'dist', 'iife', 'index.min.js'),
format: 'iife',
name: 'WebVoiceProcessor',
name: iifeBundleName,
sourcemap: false,
plugins: [terser()],
},
],
plugins: [
nodeResolve({ extensions }),
commonjs(),
workerLoader({ targetPlatform: 'browser' }),
workerLoader({ targetPlatform: 'browser', sourcemap: false }),
typescript({
typescript: require('typescript'),
cacheRoot: path.resolve(__dirname, '.rts2_cache'),
Expand All @@ -57,6 68,8 @@ export default {
babelHelpers: 'runtime',
exclude: '**/node_modules/**',
}),
sourceMaps(),
base64({
include: ['../lib/**/*.wasm', './src/**/*.js']
})
],
};
43 changes: 43 additions & 0 deletions package/src/audio_worklet/recorder_processor.js
Original file line number Diff line number Diff line change
@@ -0,0 1,43 @@
class RecorderProcessor extends AudioWorkletProcessor {
constructor(options) {
super();

const { numberOfChannels = 1, frameLength = 512 } = options?.processorOptions;

this._numberOfChannels = numberOfChannels;
this._frameLength = frameLength;

this._copied = 0;
this._recorderBuffer = new Array(numberOfChannels).fill(new Float32Array(frameLength));
}

process(inputs, outputs, parameters) {
let input = inputs[0]; // get first input
if (input.length === 0) {
return true;
}

let remaining = input[0].length;
while (remaining > 0) {
const toCopy = Math.min(remaining, this._frameLength - this._copied);

for (let ch = 0; ch < this._numberOfChannels; ch ) {
this._recorderBuffer[ch].set(input[ch].slice(0, toCopy), this._copied);
}

remaining -= toCopy;
this._copied = toCopy;

if (this._copied >= this._frameLength) {
this.port.postMessage({
buffer: this._recorderBuffer
});
this._copied = 0;
}
}

return true;
}
}

registerProcessor('recorder-processor', RecorderProcessor);
Loading

0 comments on commit 448e9b5

Please sign in to comment.