Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 committed Jun 1, 2024
1 parent d1fdc65 commit 995dd53
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 46 deletions.
3 changes: 2 additions & 1 deletion recipes/llm-voice-assistant/web/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
dist
lib
rollup.config.js
.eslintrc.js
.eslintrc.js
types
15 changes: 3 additions & 12 deletions recipes/llm-voice-assistant/web/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ module.exports = {
files: ['src/**/*.ts'],
extends: ['plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/no-parameter-properties': 2,
'@typescript-eslint/no-parameter-properties': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-var-requires': 2,
'@typescript-eslint/no-non-null-assertion': 0,
'@typescript-eslint/no-use-before-define': 2,
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/no-empty-interface': 2,
'@typescript-eslint/explicit-function-return-type': 2,
Expand All @@ -37,15 +37,6 @@ module.exports = {
],
'@typescript-eslint/no-shadow': 2
}
},
{
files: ['test/**/*.ts', 'cypress/**/*.ts'],
extends: ['plugin:cypress/recommended'],
rules: {
'no-unused-expressions': 0,
'no-unused-vars': 0,
'cypress/unsafe-to-chain-command': 0
}
}
],

Expand Down Expand Up @@ -269,7 +260,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
2 changes: 2 additions & 0 deletions recipes/llm-voice-assistant/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ or using `npm`:
npm run start
```

<!-- markdown-link-check-disable -->
3. Open [localhost:5000](http://localhost:5000) in your web browser.
<!-- markdown-link-check-enable -->

4. Enter your AccessKey and upload your`picoLLM` model file which can be obtained from
[Picovoice Console](https://console.picovoice.ai/). Then press `Init Voice Assistant`.
1 change: 1 addition & 0 deletions recipes/llm-voice-assistant/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"build:all": "rollup --config --bundleConfigAsCjs",
"build:types": "tsc --declaration --declarationMap --emitDeclarationOnly --outDir ./types",
"build": "npm-run-all --parallel build:**",
"lint": "eslint . --ext .js,.ts",
"start": "yarn run http-server -a localhost -p 5000"
},
"keywords": [
Expand Down
14 changes: 7 additions & 7 deletions recipes/llm-voice-assistant/web/src/audio_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@ class AudioStream {
this._sampleRate = sampleRate;
this._audioContext = new (window.AudioContext ||
// @ts-ignore
window.webKitAudioContext)({ sampleRate: sampleRate })
window.webKitAudioContext)({ sampleRate: sampleRate });

this._audioGain = this._audioContext.createGain();
this._audioGain.gain.value = 1;
this._audioGain.connect(this._audioContext.destination);
}

public stream(pcm: Int16Array) {
public stream(pcm: Int16Array): void {
this._audioBuffers.push(this.createBuffer(pcm));
}

public play() {
public play(): void {
if (this._isPlaying) {
return;
}
if (this._audioBuffers.length === 0) {
return;
}

const streamSource = this._audioContext.createBufferSource();
const streamSource = this._audioContext.createBufferSource();

streamSource.buffer = this._audioBuffers.shift() ?? null;
streamSource.connect(this._audioGain);

streamSource.onended = () => {
streamSource.onended = (): void => {
this._isPlaying = false;
if (this._audioBuffers.length > 0) {
this.play();
}
}
};

streamSource.start();
this._isPlaying = true;
}

public async waitPlayback() {
public async waitPlayback(): Promise<void> {
return new Promise<void>(resolve => {
const interval = setInterval(() => {
if (this._audioBuffers.length === 0 && !this._isPlaying) {
Expand Down
31 changes: 15 additions & 16 deletions recipes/llm-voice-assistant/web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const init = async (accessKey: string, {
onText,
onStream,
onComplete,
}: PvCallback) => {
}: PvCallback): Promise<void> => {
if (object !== null) {
return;
}

const detectionCallback = async (detection: PorcupineDetection) => {
const detectionCallback = async (detection: PorcupineDetection): Promise<void> => {
if (detection.index === 0) {
await WebVoiceProcessor.unsubscribe(porcupine);
await WebVoiceProcessor.subscribe(cheetah);
Expand All @@ -54,7 +54,7 @@ const init = async (accessKey: string, {
publicPath: "models/porcupine_params.pv"
});

const transcriptCallback = async (transcript: CheetahTranscript) => {
const transcriptCallback = async (transcript: CheetahTranscript): Promise<void> => {
if (transcript.isEndpoint) {
await WebVoiceProcessor.unsubscribe(cheetah);
cheetah.flush();
Expand Down Expand Up @@ -97,12 +97,12 @@ const init = async (accessKey: string, {
let stopTokens = 0;

const stopPhrases = [
'</s>', // Llama-2, Mistral, and Mixtral
'<end_of_turn>', // Gemma
'<|endoftext|>', // Phi-2
'</s>', // Llama-2, Mistral, and Mixtral
'<end_of_turn>', // Gemma
'<|endoftext|>', // Phi-2
];

const onCheetahFlushed = async () => {
const onCheetahFlushed = async (): Promise<void> => {
const prompt = transcripts.join('');
transcripts = [];
dialog.addHumanRequest(prompt);
Expand All @@ -111,7 +111,7 @@ const init = async (accessKey: string, {
completionTokenLimit: 128,
temperature: 0.7,
topP: 0.6,
streamCallback: async (token) => {
streamCallback: async token => {
if (!stopPhrases.includes(token)) {
onText(token);
await mutex.acquire();
Expand All @@ -128,7 +128,7 @@ const init = async (accessKey: string, {
});
dialog.addLLMResponse(completion);

const waitForSynthesize = () => new Promise<void>(resolve => {
const waitForSynthesize = (): Promise<void> => new Promise<void>(resolve => {
const interval = setInterval(() => {
if (synthesized === (completionTokens.length - stopTokens)) {
clearInterval(interval);
Expand Down Expand Up @@ -157,23 +157,22 @@ const init = async (accessKey: string, {
};
};

const start = async () => {
const start = async (): Promise<void> => {
if (object === null) {
return;
}

await WebVoiceProcessor.subscribe(object.porcupine);
}
};

const getStreamSampleRate = () => {
const getStreamSampleRate = (): number => {
if (object) {
return object.orca.sampleRate;
} else {
return 0;
}
}
return 0;
};

const release = async () => {
const release = async (): Promise<void> => {
if (object === null) {
return;
}
Expand Down
18 changes: 9 additions & 9 deletions recipes/llm-voice-assistant/web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1551,9 +1551,9 @@ callsites@^3.0.0:
integrity sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==

caniuse-lite@^1.0.30001587:
version "1.0.30001624"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001624.tgz#0ec4c8fa7a46e5b785477c70b38a56d0b10058eb"
integrity sha512-0dWnQG87UevOCPYaOR49CBcLBwoZLpws+k6W37nLjWUhumP1Isusj0p2u+3KhjNloRWK9OKMgjBBzPujQHw4nA==
version "1.0.30001625"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001625.tgz#ead1b155ea691d6a87938754d3cb119c24465b03"
integrity sha512-4KE9N2gcRH+HQhpeiRZXd+1niLB/XNLAhSy4z7fI8EzcbcPoAqjNInxVHTiTwWfTIV4w096XG8OtCOCQQKPv3w==

chalk@^2.4.1, chalk@^2.4.2:
version "2.4.2"
Expand Down Expand Up @@ -1688,9 +1688,9 @@ debug@^3.2.7:
ms "^2.1.1"

debug@^4.1.0, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.4:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
version "4.3.5"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.5.tgz#e83444eceb9fedd4a1da56d671ae2446a01a6e1e"
integrity sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==
dependencies:
ms "2.1.2"

Expand Down Expand Up @@ -1737,9 +1737,9 @@ doctrine@^3.0.0:
esutils "^2.0.2"

electron-to-chromium@^1.4.668:
version "1.4.783"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.783.tgz#933887165b8b6025a81663d2d97cf4b85cde27b2"
integrity sha512-bT0jEz/Xz1fahQpbZ1D7LgmPYZ3iHVY39NcWWro1+hA2IvjiPeaXtfSqrQ+nXjApMvQRE2ASt1itSLRrebHMRQ==
version "1.4.787"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.787.tgz#3eedd0a3b8be2b9e96e21675d399786ad90b99ed"
integrity sha512-d0EFmtLPjctczO3LogReyM2pbBiiZbnsKnGF+cdZhsYzHm/A0GV7W94kqzLD8SN4O3f3iHlgLUChqghgyznvCQ==

error-ex@^1.3.1:
version "1.3.2"
Expand Down
11 changes: 10 additions & 1 deletion res/.lint/spell-check/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
}
],
"ignorePaths": [
"**/__pycache__/**"
"**/__pycache__/**",

// javascript
"**/package.json",
"**/packages-lock.json",
"**/tsconfig.json",
"**/tslint.json",

// common
"**/*.pv"
]
}
1 change: 1 addition & 0 deletions res/.lint/spell-check/dict.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dotdotdot
dtype
endoftext
logit
Expand Down

0 comments on commit 995dd53

Please sign in to comment.