Skip to content

Commit b0061d8

Browse files
authored
Extra error handling
2 parents 68e72f3 + eafbd21 commit b0061d8

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"author": "Picovoice Inc",
1818
"license": "Apache-2.0",
1919
"dependencies": {
20-
"@picovoice/web-voice-processor": "^4.0.4",
20+
"@picovoice/web-voice-processor": "^4.0.6",
2121
"http-server": "^14.0.0",
2222
"wavefile": "^11.0.0"
2323
}

demo/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# yarn lockfile v1
33

44

5-
"@picovoice/web-voice-processor@^4.0.4":
6-
version "4.0.4"
7-
resolved "https://registry.yarnpkg.com/@picovoice/web-voice-processor/-/web-voice-processor-4.0.4.tgz#12140c9a0120e0db9dda80bcf00d7f827f1a8c99"
8-
integrity sha512-WZ4PPXU0i/yPzIjd+jbx9VSMF6Shbyf2BXt2U7a6MASJ2KWeG9+zDx6nteDF10cyG3T78G+4EB24tLsdyLVmWw==
5+
"@picovoice/web-voice-processor@^4.0.6":
6+
version "4.0.6"
7+
resolved "https://registry.yarnpkg.com/@picovoice/web-voice-processor/-/web-voice-processor-4.0.6.tgz#4769283b82f64d3625794f7290d47c6d477a3f41"
8+
integrity sha512-Ykfy6hrWFpOklfeN7rSJb5CGim8wDu7J+l8imRYyQxWHWVV1Wu5S8FW69zkJmwiDG2Wx+M2+h0SCMS+hNM5qow==
99

1010
ansi-styles@^4.1.0:
1111
version "4.3.0"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@picovoice/web-voice-processor",
3-
"version": "4.0.5",
3+
"version": "4.0.6",
44
"description": "Real-time audio processing for voice, in web browsers",
55
"entry": "src/index.ts",
66
"module": "dist/esm/index.js",

src/web_voice_processor.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ export class WebVoiceProcessor {
9393
*/
9494
public static async subscribe(engines: PvEngine | PvEngine[]): Promise<void> {
9595
for (const engine of (Array.isArray(engines) ? engines : [engines])) {
96+
if (!engine) {
97+
throw new WvpError("InvalidEngine", "Null or undefined engine.");
98+
}
99+
96100
if (engine.worker) {
97101
if (engine.worker.postMessage && typeof engine.worker.postMessage === 'function') {
98102
this.instance()._engines.add(engine);
@@ -195,21 +199,23 @@ export class WebVoiceProcessor {
195199
await this._audioContext.resume();
196200
}
197201
} catch (error: any) {
198-
if (error.name === 'SecurityError' || error.name === 'NotAllowedError') {
199-
throw new WvpError(
200-
'PermissionError',
201-
'Failed to record audio: microphone permissions denied.'
202-
);
203-
} else if (error.name === 'NotFoundError' || error.name === 'OverconstrainedError') {
204-
throw new WvpError(
205-
'DeviceMissingError',
206-
'Failed to record audio: audio recording device was not found.'
207-
);
208-
} else if (error.name === 'NotReadableError') {
209-
throw new WvpError(
210-
'DeviceReadError',
211-
'Failed to record audio: audio recording device is not working correctly.'
212-
);
202+
if (error && error.name) {
203+
if (error.name === 'SecurityError' || error.name === 'NotAllowedError') {
204+
throw new WvpError(
205+
'PermissionError',
206+
'Failed to record audio: microphone permissions denied.'
207+
);
208+
} else if (error.name === 'NotFoundError' || error.name === 'OverconstrainedError') {
209+
throw new WvpError(
210+
'DeviceMissingError',
211+
'Failed to record audio: audio recording device was not found.'
212+
);
213+
} else if (error.name === 'NotReadableError') {
214+
throw new WvpError(
215+
'DeviceReadError',
216+
'Failed to record audio: audio recording device is not working correctly.'
217+
);
218+
}
213219
} else {
214220
throw error;
215221
}

0 commit comments

Comments
 (0)