@open-mic/svelte 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +37 -2
- package/dist/index.cjs +60 -0
- package/dist/index.d.cts +18 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +35 -0
- package/package.json +48 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hugh Williams
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @open-mic/svelte
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Svelte store for [`@open-mic/core`](../core): record the microphone, stream it in chunks as it goes, and get the
|
|
4
|
+
whole recording back. Works in Svelte 3, 4 and 5.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install @open-mic/svelte
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```svelte
|
|
11
|
+
<script>
|
|
12
|
+
import { createRecording } from '@open-mic/svelte';
|
|
13
|
+
|
|
14
|
+
const recording = createRecording({ onAudio: chunk => doSomething(chunk) });
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<button onclick={$recording.isRecording ? recording.stop : recording.record}>
|
|
18
|
+
{$recording.isRecording ? 'Stop' : 'Record'}
|
|
19
|
+
</button>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`createRecording(options?)` takes everything [`@open-mic/core`](../core)'s `Microphone.create` and `record` take (except `signal`).
|
|
23
|
+
It's a store of `{ isRecording, blob, error }`, with:
|
|
24
|
+
|
|
25
|
+
| | |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `record()` | Starts a recording, asking for the mic the first time. Does nothing if already recording. |
|
|
28
|
+
| `stop()` | Ends it. `blob` updates once the last chunk is in. |
|
|
29
|
+
| `level()` | Loudness from 0 to 1 while recording, for a meter |
|
|
30
|
+
| `mimeType` | The format it records in |
|
|
31
|
+
|
|
32
|
+
`error` is why the last recording failed: `NotAllowedError`, `NotFoundError` or a recorder error. When the last
|
|
33
|
+
subscriber goes (the component using `$recording` is destroyed), any recording stops and the mic turns off. A store
|
|
34
|
+
nobody subscribes to has nothing to tell it it's finished, so call `stop()` yourself if you use one outside a component.
|
|
35
|
+
|
|
36
|
+
## Licence
|
|
37
|
+
|
|
38
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createRecording: () => createRecording
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_store = require("svelte/store");
|
|
27
|
+
var import_core = require("@open-mic/core");
|
|
28
|
+
var createRecording = ({ onAudio, chunkMs, maxMs, ...micOptions } = {}) => {
|
|
29
|
+
const mic = import_core.Microphone.create(micOptions);
|
|
30
|
+
const current = (0, import_store.writable)(void 0);
|
|
31
|
+
const outcome = (0, import_store.writable)({});
|
|
32
|
+
const stop = () => void (0, import_store.get)(current)?.stop();
|
|
33
|
+
const state = (0, import_store.derived)([current, outcome], ([recording, ended]) => ({ ...ended, isRecording: !!recording }));
|
|
34
|
+
return {
|
|
35
|
+
subscribe: (0, import_store.readable)({ isRecording: false }, (set) => {
|
|
36
|
+
const unsubscribe = state.subscribe(set);
|
|
37
|
+
return () => {
|
|
38
|
+
unsubscribe();
|
|
39
|
+
stop();
|
|
40
|
+
};
|
|
41
|
+
}).subscribe,
|
|
42
|
+
record: () => {
|
|
43
|
+
if ((0, import_store.get)(current)) return;
|
|
44
|
+
outcome.update(({ blob }) => ({ blob }));
|
|
45
|
+
const recording = mic.record({ onAudio, chunkMs, maxMs });
|
|
46
|
+
current.set(recording);
|
|
47
|
+
recording.then(
|
|
48
|
+
(blob) => outcome.set({ blob }),
|
|
49
|
+
(error) => outcome.update(({ blob }) => ({ blob, error }))
|
|
50
|
+
).finally(() => current.set(void 0));
|
|
51
|
+
},
|
|
52
|
+
stop,
|
|
53
|
+
level: () => (0, import_store.get)(current)?.level() ?? 0,
|
|
54
|
+
mimeType: mic.mimeType
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
createRecording
|
|
60
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Readable } from 'svelte/store';
|
|
2
|
+
import { MicrophoneOptions, RecordOptions } from '@open-mic/core';
|
|
3
|
+
|
|
4
|
+
type RecordingOptions = MicrophoneOptions & Omit<RecordOptions, 'signal'>;
|
|
5
|
+
interface RecordingState {
|
|
6
|
+
readonly isRecording: boolean;
|
|
7
|
+
readonly blob?: Blob;
|
|
8
|
+
readonly error?: Error;
|
|
9
|
+
}
|
|
10
|
+
interface RecordingStore extends Readable<RecordingState> {
|
|
11
|
+
record(): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
level(): number;
|
|
14
|
+
readonly mimeType: string;
|
|
15
|
+
}
|
|
16
|
+
declare const createRecording: ({ onAudio, chunkMs, maxMs, ...micOptions }?: RecordingOptions) => RecordingStore;
|
|
17
|
+
|
|
18
|
+
export { type RecordingOptions, type RecordingState, type RecordingStore, createRecording };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Readable } from 'svelte/store';
|
|
2
|
+
import { MicrophoneOptions, RecordOptions } from '@open-mic/core';
|
|
3
|
+
|
|
4
|
+
type RecordingOptions = MicrophoneOptions & Omit<RecordOptions, 'signal'>;
|
|
5
|
+
interface RecordingState {
|
|
6
|
+
readonly isRecording: boolean;
|
|
7
|
+
readonly blob?: Blob;
|
|
8
|
+
readonly error?: Error;
|
|
9
|
+
}
|
|
10
|
+
interface RecordingStore extends Readable<RecordingState> {
|
|
11
|
+
record(): void;
|
|
12
|
+
stop(): void;
|
|
13
|
+
level(): number;
|
|
14
|
+
readonly mimeType: string;
|
|
15
|
+
}
|
|
16
|
+
declare const createRecording: ({ onAudio, chunkMs, maxMs, ...micOptions }?: RecordingOptions) => RecordingStore;
|
|
17
|
+
|
|
18
|
+
export { type RecordingOptions, type RecordingState, type RecordingStore, createRecording };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { derived, get, readable, writable } from "svelte/store";
|
|
3
|
+
import { Microphone } from "@open-mic/core";
|
|
4
|
+
var createRecording = ({ onAudio, chunkMs, maxMs, ...micOptions } = {}) => {
|
|
5
|
+
const mic = Microphone.create(micOptions);
|
|
6
|
+
const current = writable(void 0);
|
|
7
|
+
const outcome = writable({});
|
|
8
|
+
const stop = () => void get(current)?.stop();
|
|
9
|
+
const state = derived([current, outcome], ([recording, ended]) => ({ ...ended, isRecording: !!recording }));
|
|
10
|
+
return {
|
|
11
|
+
subscribe: readable({ isRecording: false }, (set) => {
|
|
12
|
+
const unsubscribe = state.subscribe(set);
|
|
13
|
+
return () => {
|
|
14
|
+
unsubscribe();
|
|
15
|
+
stop();
|
|
16
|
+
};
|
|
17
|
+
}).subscribe,
|
|
18
|
+
record: () => {
|
|
19
|
+
if (get(current)) return;
|
|
20
|
+
outcome.update(({ blob }) => ({ blob }));
|
|
21
|
+
const recording = mic.record({ onAudio, chunkMs, maxMs });
|
|
22
|
+
current.set(recording);
|
|
23
|
+
recording.then(
|
|
24
|
+
(blob) => outcome.set({ blob }),
|
|
25
|
+
(error) => outcome.update(({ blob }) => ({ blob, error }))
|
|
26
|
+
).finally(() => current.set(void 0));
|
|
27
|
+
},
|
|
28
|
+
stop,
|
|
29
|
+
level: () => get(current)?.level() ?? 0,
|
|
30
|
+
mimeType: mic.mimeType
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
createRecording
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mic/svelte",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Svelte store for @open-mic/core: record the microphone, stream it in chunks, and get the whole recording back.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"microphone",
|
|
7
|
+
"mediarecorder",
|
|
8
|
+
"audio",
|
|
9
|
+
"recording",
|
|
10
|
+
"svelte",
|
|
11
|
+
"store"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Hugh Williams",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/HughWilliams90/open-mic.git",
|
|
18
|
+
"directory": "packages/svelte"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/HughWilliams90/open-mic#readme",
|
|
21
|
+
"bugs": "https://github.com/HughWilliams90/open-mic/issues",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "./dist/index.cjs",
|
|
24
|
+
"module": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"sideEffects": false,
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup src/index.ts --format esm,cjs --dts --clean --external svelte --external @open-mic/core",
|
|
39
|
+
"prepublishOnly": "npm run build"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@open-mic/core": "^0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"svelte": ">=3"
|
|
49
|
+
}
|
|
50
|
+
}
|