@prosopo/audio-assets 0.0.0-stage → 0.2.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/.turbo/turbo-build$colon$cjs.log +23 -0
- package/.turbo/turbo-build$colon$tsc.log +14 -0
- package/.turbo/turbo-build.log +25 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE +201 -0
- package/dist/_virtual/_rolldown/runtime.js +3 -0
- package/dist/cjs/distort.cjs +91 -0
- package/dist/cjs/encode.cjs +40 -0
- package/dist/cjs/index.cjs +109 -0
- package/dist/cjs/levels.cjs +18 -0
- package/dist/cjs/phonemes.cjs +217 -0
- package/dist/cjs/synth.cjs +222 -0
- package/dist/distort.d.ts +7 -0
- package/dist/distort.d.ts.map +1 -0
- package/dist/distort.js +88 -0
- package/dist/distort.js.map +1 -0
- package/dist/encode.d.ts +4 -0
- package/dist/encode.d.ts.map +1 -0
- package/dist/encode.js +39 -0
- package/dist/encode.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/levels.d.ts +3 -0
- package/dist/levels.d.ts.map +1 -0
- package/dist/levels.js +17 -0
- package/dist/levels.js.map +1 -0
- package/dist/phonemes.d.ts +4 -0
- package/dist/phonemes.d.ts.map +1 -0
- package/dist/phonemes.js +216 -0
- package/dist/phonemes.js.map +1 -0
- package/dist/synth.d.ts +13 -0
- package/dist/synth.d.ts.map +1 -0
- package/dist/synth.js +220 -0
- package/dist/synth.js.map +1 -0
- package/dist/tests/audioAssets.unit.test.d.ts +2 -0
- package/dist/tests/audioAssets.unit.test.d.ts.map +1 -0
- package/dist/tests/audioAssets.unit.test.js +220 -0
- package/dist/tests/audioAssets.unit.test.js.map +1 -0
- package/dist/types.d.ts +35 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +52 -3
- package/scripts/preview.ts +141 -0
- package/vite.cjs.config.ts +23 -0
- package/vite.esm.config.ts +20 -0
- package/vite.test.config.ts +32 -0
- package/README.md +0 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
$ NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
|
|
2
|
+
ViteCommonJSConfig: .
|
|
3
|
+
{
|
|
4
|
+
tsConfigPaths: [
|
|
5
|
+
'/home/g/bench/captcha-private5/captcha/packages/puzzle-assets/tsconfig.json'
|
|
6
|
+
]
|
|
7
|
+
}
|
|
8
|
+
{ externals: [ '@prosopo/puzzle-assets' ] }
|
|
9
|
+
The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead.
|
|
10
|
+
vite v8.1.5 building ssr environment for production...
|
|
11
|
+
Bundle build started
|
|
12
|
+
[2K
|
|
13
|
+
✓ 7 modules transformed.
|
|
14
|
+
rendering chunks...
|
|
15
|
+
computing gzip size...
|
|
16
|
+
dist/cjs/levels.cjs 0.59 kB │ gzip: 0.32 kB
|
|
17
|
+
dist/cjs/encode.cjs 1.49 kB │ gzip: 0.68 kB
|
|
18
|
+
dist/cjs/distort.cjs 3.31 kB │ gzip: 1.30 kB
|
|
19
|
+
dist/cjs/phonemes.cjs 3.52 kB │ gzip: 1.12 kB
|
|
20
|
+
dist/cjs/index.cjs 4.67 kB │ gzip: 1.70 kB
|
|
21
|
+
dist/cjs/synth.cjs 7.70 kB │ gzip: 2.73 kB
|
|
22
|
+
|
|
23
|
+
✓ built in 84ms
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
$ tsc --build --verbose
|
|
2
|
+
09:15:31 - Projects in this build:
|
|
3
|
+
* ../../dev/config/tsconfig.json
|
|
4
|
+
* ../puzzle-assets/tsconfig.json
|
|
5
|
+
* tsconfig.json
|
|
6
|
+
|
|
7
|
+
09:15:31 - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/vite/vite.frontend.config.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
|
|
8
|
+
|
|
9
|
+
09:15:32 - Project '../puzzle-assets/tsconfig.json' is up to date because newest input '../puzzle-assets/src/types.ts' is older than output '../puzzle-assets/tsconfig.tsbuildinfo'
|
|
10
|
+
|
|
11
|
+
09:15:32 - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
|
|
12
|
+
|
|
13
|
+
09:15:32 - Building project '/home/g/bench/captcha-private5/captcha/packages/audio-assets/tsconfig.json'...
|
|
14
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
$ pnpm run build:cross-env --mode ${NODE_ENV:-development}
|
|
2
|
+
$ vite build --config vite.esm.config.ts --mode production
|
|
3
|
+
ViteEsmConfig: .
|
|
4
|
+
{
|
|
5
|
+
tsConfigPaths: [
|
|
6
|
+
'/home/g/bench/captcha-private5/captcha/packages/puzzle-assets/tsconfig.json'
|
|
7
|
+
]
|
|
8
|
+
}
|
|
9
|
+
{ externals: [ '@prosopo/puzzle-assets' ] }
|
|
10
|
+
The plugin "vite-tsconfig-paths" is detected. Vite now supports tsconfig paths resolution natively via the resolve.tsconfigPaths option. You can remove the plugin and set resolve.tsconfigPaths: true in your Vite config instead.
|
|
11
|
+
vite v8.1.5 building ssr environment for production...
|
|
12
|
+
Bundle build started
|
|
13
|
+
[2K
|
|
14
|
+
✓ 7 modules transformed.
|
|
15
|
+
rendering chunks...
|
|
16
|
+
computing gzip size...
|
|
17
|
+
dist/_virtual/_rolldown/runtime.js 0.04 kB │ gzip: 0.06 kB
|
|
18
|
+
dist/levels.js 0.57 kB │ gzip: 0.32 kB
|
|
19
|
+
dist/encode.js 1.47 kB │ gzip: 0.67 kB
|
|
20
|
+
dist/distort.js 3.19 kB │ gzip: 1.27 kB
|
|
21
|
+
dist/phonemes.js 3.49 kB │ gzip: 1.11 kB
|
|
22
|
+
dist/index.js 3.81 kB │ gzip: 1.54 kB
|
|
23
|
+
dist/synth.js 7.61 kB │ gzip: 2.72 kB
|
|
24
|
+
|
|
25
|
+
✓ built in 153ms
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @prosopo/audio-assets
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
### Minor Changes
|
|
5
|
+
|
|
6
|
+
- b299a91: An audio challenge, offered only as an accessibility alternative, like reCAPTCHA's audio option. The user hears a short sequence of spoken digits and types them in.
|
|
7
|
+
|
|
8
|
+
It is off by default and needs two switches. Prosopo has to turn on the `captchaTypeFeatureFlags.audio` feature flag for the site, which the site owner cannot do, and the site owner has to set `audioAccessibilityEnabled`. When both are on, image, puzzle and icon-order challenges show a "Use audio instead" button. Pressing it swaps the visual challenge for the audio one. After a wrong answer the user stays on audio and gets a fresh clip.
|
|
9
|
+
|
|
10
|
+
Audio is never a captcha type that can be selected or routed to. A site's `captchaType`, traffic-filter categories, Restrict rules and the site-key CLI all reject it, and routing, PoW escalation and the severity tiers leave it out. The provider only serves audio against the visual session the user was already given, and only on a site with both switches on; any other audio request is refused before the session is used up, and a request without a session is always refused.
|
|
11
|
+
|
|
12
|
+
The spoken digits are synthesised by `@prosopo/audio-assets`, so there is no recorded set of clips to collect. The answer never leaves the provider, and a challenge can be submitted and verified only once, even under concurrent requests. `@prosopo/procaptcha-audio` is the widget. It and the "Use audio instead" button are built on the shared widget code in `@prosopo/procaptcha-common`, and the provider side is built on the shared interactive-captcha code that puzzle and icon-order use.
|
|
13
|
+
|
|
14
|
+
The demo playground has audio pages, and there is an end-to-end test for it.
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [e13d7a8]
|
|
19
|
+
- @prosopo/puzzle-assets@0.2.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2022 PROSOPO LIMITED
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const require_levels = require("./levels.cjs");
|
|
2
|
+
//#region src/distort.ts
|
|
3
|
+
var REVERB_COMB_DELAYS_MS = [
|
|
4
|
+
29.7,
|
|
5
|
+
37.1,
|
|
6
|
+
41.1,
|
|
7
|
+
43.7
|
|
8
|
+
];
|
|
9
|
+
var REVERB_COMB_FEEDBACK = .72;
|
|
10
|
+
var REVERB_ALLPASS_DELAYS_MS = [5, 1.7];
|
|
11
|
+
var REVERB_ALLPASS_FEEDBACK = .5;
|
|
12
|
+
var SOFT_CLIP_DRIVE = 1.2;
|
|
13
|
+
var OUTPUT_PEAK = .92;
|
|
14
|
+
/** Adds `source` into `target` from `offset`; anything past the end is dropped. */
|
|
15
|
+
var mixInto = (target, source, offset, gain) => {
|
|
16
|
+
const start = Math.max(0, Math.floor(offset));
|
|
17
|
+
const count = Math.min(source.length, target.length - start);
|
|
18
|
+
for (let n = 0; n < count; n++) target[start + n] = (target[start + n] ?? 0) + (source[n] ?? 0) * gain;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Pink-ish noise at `snrDb` below the signal's RMS. Pink rather than white
|
|
22
|
+
* because white noise spends its energy above the formants and masks little.
|
|
23
|
+
*/
|
|
24
|
+
var addNoiseBed = (buffer, prng, snrDb) => {
|
|
25
|
+
const signalRms = require_levels.rms(buffer.samples);
|
|
26
|
+
if (signalRms === 0) return;
|
|
27
|
+
const targetRms = signalRms / 10 ** (snrDb / 20);
|
|
28
|
+
let b0 = 0;
|
|
29
|
+
let b1 = 0;
|
|
30
|
+
let b2 = 0;
|
|
31
|
+
const noise = new Float32Array(buffer.samples.length);
|
|
32
|
+
for (let n = 0; n < noise.length; n++) {
|
|
33
|
+
const white = prng.next() * 2 - 1;
|
|
34
|
+
b0 = .99765 * b0 + white * .099;
|
|
35
|
+
b1 = .963 * b1 + white * .2965;
|
|
36
|
+
b2 = .57 * b2 + white * 1.0526;
|
|
37
|
+
noise[n] = (b0 + b1 + b2 + white * .1848) * .2;
|
|
38
|
+
}
|
|
39
|
+
const noiseRms = require_levels.rms(noise);
|
|
40
|
+
if (noiseRms === 0) return;
|
|
41
|
+
mixInto(buffer.samples, noise, 0, targetRms / noiseRms);
|
|
42
|
+
};
|
|
43
|
+
var delaySamples = (delayMs, sampleRate) => Math.max(1, Math.round(delayMs / 1e3 * sampleRate));
|
|
44
|
+
/**
|
|
45
|
+
* Schroeder reverb: parallel combs into series allpasses. Its purpose is to
|
|
46
|
+
* smear onsets, which otherwise make it easy to chop the clip into
|
|
47
|
+
* one-digit segments and classify each in isolation.
|
|
48
|
+
*/
|
|
49
|
+
var addReverb = (buffer, mix) => {
|
|
50
|
+
if (mix <= 0) return;
|
|
51
|
+
const { samples, sampleRate } = buffer;
|
|
52
|
+
const wet = new Float32Array(samples.length);
|
|
53
|
+
for (const delayMs of REVERB_COMB_DELAYS_MS) {
|
|
54
|
+
const delay = delaySamples(delayMs, sampleRate);
|
|
55
|
+
const line = new Float32Array(delay);
|
|
56
|
+
let index = 0;
|
|
57
|
+
for (let n = 0; n < samples.length; n++) {
|
|
58
|
+
const delayed = line[index] ?? 0;
|
|
59
|
+
wet[n] = (wet[n] ?? 0) + delayed / REVERB_COMB_DELAYS_MS.length;
|
|
60
|
+
line[index] = (samples[n] ?? 0) + delayed * REVERB_COMB_FEEDBACK;
|
|
61
|
+
index = (index + 1) % delay;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
for (const delayMs of REVERB_ALLPASS_DELAYS_MS) {
|
|
65
|
+
const delay = delaySamples(delayMs, sampleRate);
|
|
66
|
+
const line = new Float32Array(delay);
|
|
67
|
+
let index = 0;
|
|
68
|
+
for (let n = 0; n < wet.length; n++) {
|
|
69
|
+
const input = wet[n] ?? 0;
|
|
70
|
+
const delayed = line[index] ?? 0;
|
|
71
|
+
line[index] = input + delayed * REVERB_ALLPASS_FEEDBACK;
|
|
72
|
+
wet[n] = -input * REVERB_ALLPASS_FEEDBACK + delayed;
|
|
73
|
+
index = (index + 1) % delay;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (let n = 0; n < samples.length; n++) samples[n] = (samples[n] ?? 0) * (1 - mix) + (wet[n] ?? 0) * mix;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* tanh soft clip, then normalise: hard clipping at 16-bit conversion is
|
|
80
|
+
* audibly nasty and a distinctive artefact.
|
|
81
|
+
*/
|
|
82
|
+
var finalise = (buffer) => {
|
|
83
|
+
const { samples } = buffer;
|
|
84
|
+
for (let n = 0; n < samples.length; n++) samples[n] = Math.tanh((samples[n] ?? 0) * SOFT_CLIP_DRIVE);
|
|
85
|
+
require_levels.normalise(samples, OUTPUT_PEAK);
|
|
86
|
+
};
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.addNoiseBed = addNoiseBed;
|
|
89
|
+
exports.addReverb = addReverb;
|
|
90
|
+
exports.finalise = finalise;
|
|
91
|
+
exports.mixInto = mixInto;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/encode.ts
|
|
2
|
+
var RIFF_HEADER_BYTES = 44;
|
|
3
|
+
var RIFF_PREAMBLE_BYTES = 8;
|
|
4
|
+
var FMT_CHUNK_BYTES = 16;
|
|
5
|
+
var BITS_PER_SAMPLE = 16;
|
|
6
|
+
var BYTES_PER_SAMPLE = BITS_PER_SAMPLE / 8;
|
|
7
|
+
var CHANNELS = 1;
|
|
8
|
+
var PCM_FORMAT_TAG = 1;
|
|
9
|
+
var INT16_SCALE = 32767;
|
|
10
|
+
/**
|
|
11
|
+
* Uncompressed WAV because every browser plays 16-bit PCM with no codec
|
|
12
|
+
* dependency or artefacts that could be mistaken for the challenge.
|
|
13
|
+
*/
|
|
14
|
+
var encodeWav = (buffer) => {
|
|
15
|
+
const { samples, sampleRate } = buffer;
|
|
16
|
+
const dataBytes = samples.length * BYTES_PER_SAMPLE;
|
|
17
|
+
const out = Buffer.alloc(RIFF_HEADER_BYTES + dataBytes);
|
|
18
|
+
out.write("RIFF", 0, "ascii");
|
|
19
|
+
out.writeUInt32LE(RIFF_HEADER_BYTES - RIFF_PREAMBLE_BYTES + dataBytes, 4);
|
|
20
|
+
out.write("WAVE", 8, "ascii");
|
|
21
|
+
out.write("fmt ", 12, "ascii");
|
|
22
|
+
out.writeUInt32LE(FMT_CHUNK_BYTES, 16);
|
|
23
|
+
out.writeUInt16LE(PCM_FORMAT_TAG, 20);
|
|
24
|
+
out.writeUInt16LE(CHANNELS, 22);
|
|
25
|
+
out.writeUInt32LE(sampleRate, 24);
|
|
26
|
+
out.writeUInt32LE(sampleRate * CHANNELS * BYTES_PER_SAMPLE, 28);
|
|
27
|
+
out.writeUInt16LE(CHANNELS * BYTES_PER_SAMPLE, 32);
|
|
28
|
+
out.writeUInt16LE(BITS_PER_SAMPLE, 34);
|
|
29
|
+
out.write("data", 36, "ascii");
|
|
30
|
+
out.writeUInt32LE(dataBytes, 40);
|
|
31
|
+
for (let n = 0; n < samples.length; n++) {
|
|
32
|
+
const clamped = Math.max(-1, Math.min(1, samples[n] ?? 0));
|
|
33
|
+
out.writeInt16LE(Math.round(clamped * INT16_SCALE), RIFF_HEADER_BYTES + n * BYTES_PER_SAMPLE);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
};
|
|
37
|
+
var toDataUri = (wav) => `data:audio/wav;base64,${wav.toString("base64")}`;
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.encodeWav = encodeWav;
|
|
40
|
+
exports.toDataUri = toDataUri;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_levels = require("./levels.cjs");
|
|
3
|
+
const require_distort = require("./distort.cjs");
|
|
4
|
+
const require_encode = require("./encode.cjs");
|
|
5
|
+
const require_phonemes = require("./phonemes.cjs");
|
|
6
|
+
const require_synth = require("./synth.cjs");
|
|
7
|
+
let _prosopo_puzzle_assets = require("@prosopo/puzzle-assets");
|
|
8
|
+
//#region src/index.ts
|
|
9
|
+
/** Must match the `audio*Default` constants in `@prosopo/types` client settings. */
|
|
10
|
+
var DEFAULT_RENDER_SETTINGS = {
|
|
11
|
+
digitCount: 5,
|
|
12
|
+
noiseSnrDb: 14,
|
|
13
|
+
babbleGain: .16,
|
|
14
|
+
babbleVoices: 2,
|
|
15
|
+
reverbMix: .12,
|
|
16
|
+
gapMs: 220
|
|
17
|
+
};
|
|
18
|
+
var LEAD_IN_MS = 250;
|
|
19
|
+
var LEAD_OUT_MS = 350;
|
|
20
|
+
var GAP_JITTER_RATIO = .4;
|
|
21
|
+
var MAX_GAP_JITTER_MS = 360;
|
|
22
|
+
var BABBLE_MAX_START_MS = 400;
|
|
23
|
+
var BABBLE_MAX_PAUSE_MS = 500;
|
|
24
|
+
var msToSamples = (ms, sampleRate) => Math.round(ms / 1e3 * sampleRate);
|
|
25
|
+
/** Repeats allowed: forbidding them would let a solver narrow the last digit from the others. */
|
|
26
|
+
var chooseAnswer = (prng, count) => Array.from({ length: count }, () => prng.pick(require_phonemes.DIGITS));
|
|
27
|
+
/**
|
|
28
|
+
* Other digit names by other speakers, from the answer's own alphabet, so
|
|
29
|
+
* transcribing everything audible yields a longer string with no marker for
|
|
30
|
+
* which digits were the foreground ones.
|
|
31
|
+
*/
|
|
32
|
+
var renderBabble = (prng, lengthSamples, sampleRate, voices) => {
|
|
33
|
+
const track = new Float32Array(lengthSamples);
|
|
34
|
+
const maxStart = msToSamples(BABBLE_MAX_START_MS, sampleRate);
|
|
35
|
+
const maxPause = msToSamples(BABBLE_MAX_PAUSE_MS, sampleRate);
|
|
36
|
+
for (let v = 0; v < voices; v++) {
|
|
37
|
+
const voice = {
|
|
38
|
+
...require_synth.randomVoice(prng),
|
|
39
|
+
formantScale: prng.range(.8, 1.3),
|
|
40
|
+
rate: prng.range(.75, 1.35)
|
|
41
|
+
};
|
|
42
|
+
let cursor = prng.int(0, maxStart);
|
|
43
|
+
while (cursor < lengthSamples) {
|
|
44
|
+
const word = require_synth.synthesiseUtterance(prng.pick(require_phonemes.DIGITS), voice, prng, sampleRate);
|
|
45
|
+
require_distort.mixInto(track, word.samples, cursor, prng.range(.6, 1));
|
|
46
|
+
cursor += word.samples.length + prng.int(0, maxPause);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return track;
|
|
50
|
+
};
|
|
51
|
+
/** The returned answer must stay on the challenge record and never reach the client. */
|
|
52
|
+
var renderAudioChallenge = (settings = DEFAULT_RENDER_SETTINGS, sampleRate = require_synth.SAMPLE_RATE) => {
|
|
53
|
+
const prng = (0, _prosopo_puzzle_assets.createPrng)((0, _prosopo_puzzle_assets.createSeed)());
|
|
54
|
+
const utterances = chooseAnswer(prng, settings.digitCount);
|
|
55
|
+
const answer = utterances.map((u) => u.answer).join("");
|
|
56
|
+
const voice = require_synth.randomVoice(prng);
|
|
57
|
+
const words = utterances.map((u) => require_synth.synthesiseUtterance(u, voice, prng, sampleRate));
|
|
58
|
+
const gapSamples = msToSamples(settings.gapMs, sampleRate);
|
|
59
|
+
const leadIn = msToSamples(LEAD_IN_MS, sampleRate);
|
|
60
|
+
const leadOut = msToSamples(LEAD_OUT_MS, sampleRate);
|
|
61
|
+
const maxJitter = msToSamples(Math.min(settings.gapMs * GAP_JITTER_RATIO, MAX_GAP_JITTER_MS), sampleRate);
|
|
62
|
+
const totalSamples = leadIn + words.reduce((total, w) => total + w.samples.length, 0) + gapSamples * Math.max(0, words.length - 1) + maxJitter * words.length + leadOut;
|
|
63
|
+
const samples = new Float32Array(totalSamples);
|
|
64
|
+
let cursor = leadIn;
|
|
65
|
+
for (const word of words) {
|
|
66
|
+
require_distort.mixInto(samples, word.samples, cursor, 1);
|
|
67
|
+
cursor += word.samples.length + gapSamples + prng.int(-Math.floor(maxJitter / 2), maxJitter);
|
|
68
|
+
}
|
|
69
|
+
const buffer = {
|
|
70
|
+
samples,
|
|
71
|
+
sampleRate
|
|
72
|
+
};
|
|
73
|
+
if (settings.babbleGain > 0 && settings.babbleVoices > 0) {
|
|
74
|
+
const babble = renderBabble(prng, totalSamples, sampleRate, settings.babbleVoices);
|
|
75
|
+
require_distort.mixInto(samples, babble, 0, settings.babbleGain);
|
|
76
|
+
}
|
|
77
|
+
require_distort.addReverb(buffer, settings.reverbMix);
|
|
78
|
+
require_distort.addNoiseBed(buffer, prng, settings.noiseSnrDb);
|
|
79
|
+
require_distort.finalise(buffer);
|
|
80
|
+
return {
|
|
81
|
+
wav: require_encode.encodeWav(buffer),
|
|
82
|
+
answer,
|
|
83
|
+
durationMs: Math.round(totalSamples / sampleRate * 1e3)
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
//#endregion
|
|
87
|
+
exports.ANSWER_ALPHABET = require_phonemes.ANSWER_ALPHABET;
|
|
88
|
+
exports.DEFAULT_RENDER_SETTINGS = DEFAULT_RENDER_SETTINGS;
|
|
89
|
+
exports.DIGITS = require_phonemes.DIGITS;
|
|
90
|
+
exports.SAMPLE_RATE = require_synth.SAMPLE_RATE;
|
|
91
|
+
exports.addNoiseBed = require_distort.addNoiseBed;
|
|
92
|
+
Object.defineProperty(exports, "createPrng", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function() {
|
|
95
|
+
return _prosopo_puzzle_assets.createPrng;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, "createSeed", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function() {
|
|
101
|
+
return _prosopo_puzzle_assets.createSeed;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
exports.encodeWav = require_encode.encodeWav;
|
|
105
|
+
exports.randomVoice = require_synth.randomVoice;
|
|
106
|
+
exports.renderAudioChallenge = renderAudioChallenge;
|
|
107
|
+
exports.rms = require_levels.rms;
|
|
108
|
+
exports.synthesiseUtterance = require_synth.synthesiseUtterance;
|
|
109
|
+
exports.toDataUri = require_encode.toDataUri;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/levels.ts
|
|
2
|
+
var rms = (samples) => {
|
|
3
|
+
if (samples.length === 0) return 0;
|
|
4
|
+
let total = 0;
|
|
5
|
+
for (const value of samples) total += value * value;
|
|
6
|
+
return Math.sqrt(total / samples.length);
|
|
7
|
+
};
|
|
8
|
+
/** Scale in place so the loudest sample sits at `peak`. No-op on silence. */
|
|
9
|
+
var normalise = (samples, peak) => {
|
|
10
|
+
let max = 0;
|
|
11
|
+
for (const value of samples) max = Math.max(max, Math.abs(value));
|
|
12
|
+
if (max === 0) return;
|
|
13
|
+
const gain = peak / max;
|
|
14
|
+
for (let n = 0; n < samples.length; n++) samples[n] = (samples[n] ?? 0) * gain;
|
|
15
|
+
};
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.normalise = normalise;
|
|
18
|
+
exports.rms = rms;
|