Skip to content

Commit 648b2cc

Browse files
committed
task: Pepare for NPM publish, etc (#18)(#17)
1 parent 4406f74 commit 648b2cc

File tree

9 files changed

+106
-82
lines changed

9 files changed

+106
-82
lines changed

.github/workflows/nodejs.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on: [push]
66

77
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
88
env:
9-
NODE_VERSION: 18
9+
NODE_VERSION: 22
1010

1111
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
1212
permissions:
@@ -41,19 +41,18 @@ jobs:
4141
with:
4242
node-version: ${{ env.NODE_VERSION }}
4343
- run: npm ci
44-
- run: npm run build --if-present
44+
- run: npm run build:site --if-present
4545
- run: npm test
4646

4747
# Deploy.
4848
- name: Setup Pages
49-
uses: actions/configure-pages@v2
49+
uses: actions/configure-pages@v5
5050
- name: Upload artifact
51-
uses: actions/upload-pages-artifact@v2
51+
uses: actions/upload-pages-artifact@v3
5252
with:
53-
# Upload one directory.
54-
path: '.'
53+
path: _site
5554
- name: Deploy to GitHub Pages
5655
id: deployment
57-
uses: actions/deploy-pages@v2
56+
uses: actions/deploy-pages@v4
5857

5958
# End.

.npmignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_site
2+
.github
3+
test
4+
CHANGELOG.md
5+
LICENSE
6+
*BAK*
7+
*__.js
8+
*.ts

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright © 2020-2023 Nick Freear and contributors.
4-
3+
Copyright © 2020-2025 Nick Freear and contributors.
54

65
Permission is hereby granted, free of charge, to any person obtaining a copy
76
of this software and associated documentation files (the “Software”), to deal

_site/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.*

demo/lib/example-app.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,34 @@
88

99
// @ts-check
1010

11-
// import 'ms-cog-speech-sdk';
12-
// import { createDictationRecognizerPonyfill, getDictationRecognizerConfig, fireMockActionsEvent } from 'adapt-speech-recog';
13-
import { createAdaptiveRecognizerPonyfill, getAdaptiveRecognizerConfig, fireMockActionsEvent } from 'adaptive-speech-recog';
11+
import {
12+
createAdaptiveRecognizerPonyfill, getAdaptiveRecognizerConfig, fireMockActionsEvent
13+
} from 'adaptive-speech-recog';
1414
import { webApiSpeechRecogDemo } from 'web-speech-recog';
1515

1616
const USE_WEB_API = param(/webapi=(true)/);
1717

18-
/* const OPT = { }; */
18+
const FORM = document.querySelector('#exampleAppForm');
19+
const FORM_EL = FORM.elements;
1920

20-
const REC_START_BUTTON = document.querySelector('#recognizer-start-button');
21-
const REC_STOP_BUTTON = document.querySelector('#recognizer-stop-button');
21+
export default function exampleApp () {
22+
console.debug('Form:', FORM_EL, FORM);
2223

23-
// const SDK_SCRIPT = document.querySelector('script[ src *= ".speech.sdk." ]');
24+
console.debug('SpeechSDK:', window.SpeechSDK);
2425

25-
const LOG = document.querySelector('#log');
26-
const RESULT = document.querySelector('#result');
27-
const PRE_OPT = document.querySelector('#options');
28-
const ACTIONS = document.querySelector('#actions');
29-
const SDK_VERSION = document.querySelector('#sdk-version');
30-
31-
console.debug('SpeechSDK:', window.SpeechSDK);
32-
33-
if (USE_WEB_API) {
34-
webApiSpeechRecogDemo();
35-
} else {
36-
exampleApp();
26+
if (USE_WEB_API) {
27+
webApiSpeechRecogDemo();
28+
} else {
29+
runExampleApp();
30+
}
3731
}
3832

39-
export function exampleApp () {
33+
export function runExampleApp () {
4034
const options = getAdaptiveRecognizerConfig(); // WAS: getDictationRecognizerConfig();
4135

4236
if (!options.subscriptionKey || /_/.test(options.subscriptionKey)) {
4337
document.body.className += 'error config-error';
44-
LOG.textContent = 'ERROR: Expecting a URL parameter `?key=AZURE_SPEECH_SUBSCRIPTION_KEY`.';
38+
updateLog('ERROR: Expecting a URL parameter `?key=AZURE_SPEECH_SUBSCRIPTION_KEY`.');
4539
throw new Error('ERROR: Expecting a URL parameter `?key=AZURE_SPEECH_SUBSCRIPTION_KEY`.');
4640
}
4741

@@ -52,15 +46,15 @@ export function exampleApp () {
5246
console.debug('Ponyfill:', ponyfill);
5347

5448
recognizer.getConfiguration().then(OPT => {
55-
PRE_OPT.textContent = 'Options: ' + JSON.stringify(OPT, null, 2); // Was: '\t';
49+
FORM_EL.options.textContent = 'Options: ' + JSON.stringify(OPT, null, 2); // Was: '\t';
5650

5751
if (OPT.actionPhrasesEnable) {
5852
const actionList = fireMockActionsEvent();
5953

60-
ACTIONS.innerHTML = `Suggested actions: <q>${actionList.join('</q>, <q>')}</q>`;
54+
FORM_EL.actions.value = `Suggested actions: <q>${actionList.join('</q>, <q>')}</q>`;
6155
}
6256

63-
SDK_VERSION.innerHTML = `Speech SDK <i>${OPT.sdkVersion}</i>`;
57+
FORM_EL.sdkVersion.value = `Speech SDK ${OPT.sdkVersion}`;
6458
});
6559

6660
// recognizer.addEventListener('result', ev => console.warn('Event: result.', ev));
@@ -75,8 +69,8 @@ export function exampleApp () {
7569

7670
console.warn('Result event:', confidence, ev);
7771

78-
RESULT.textContent = TEXT; // Or: RESULT.value!
79-
LOG.textContent += `Result := ${TEXT} (${SOURCE})\n`;
72+
FORM_EL.result.value = TEXT; // Or: RESULT.value!
73+
updateLog(`Result := ${TEXT} (${SOURCE})`);
8074

8175
if (isFinal) {
8276
onRecognitionStop();
@@ -87,35 +81,35 @@ export function exampleApp () {
8781

8882
recognizer.onend = (ev) => {
8983
console.warn('End event:', ev);
90-
LOG.textContent += '> End.\n';
84+
updateLog('> End.');
9185

9286
onRecognitionStop();
9387
};
9488

95-
recognizer.onstart = ev => {
89+
recognizer.onstart = (ev) => {
9690
console.debug('Start event:', ev);
97-
LOG.textContent += '> Start\n';
91+
updateLog('> Start');
9892
};
9993

100-
recognizer.onerror = ev => {
101-
const ERROR = ev.data.error;
94+
recognizer.onerror = (ev) => {
95+
const { error } = ev.data;
10296

103-
console.error('>> ERROR:', ERROR, ev);
97+
console.error('>> ERROR:', error, ev);
10498

10599
onRecognitionStop();
106100

107101
document.body.classList.add('recognizer-error');
108-
document.body.setAttribute('data-error', ERROR);
102+
document.body.setAttribute('data-error', error);
109103

110-
if (/microphone initialization: NotAllowedError/.test(ERROR)) {
111-
LOG.textContent = '> Warning: microphone blocked.';
104+
if (/microphone initialization: NotAllowedError/.test(error)) {
105+
updateLog('> Warning: microphone blocked.');
112106
}
113107
};
114108

115109
// ----------------------------------------------------
116110
// Button events.
117111

118-
REC_START_BUTTON.addEventListener('click', async (ev) => {
112+
FORM.addEventListener('submit', async (ev) => {
119113
ev.preventDefault();
120114
onButtonStart();
121115

@@ -126,13 +120,17 @@ export function exampleApp () {
126120
// setTimeout(() => enumMediaDevices(), 5000);
127121
});
128122

129-
REC_STOP_BUTTON.addEventListener('click', ev => {
123+
FORM.addEventListener('reset', (ev) => {
130124
ev.preventDefault();
131125

132126
console.debug('Recognizer stop button clicked');
133127

134128
recognizer.stop(() => onRecognitionStop());
135129
});
130+
131+
function updateLog (value) {
132+
FORM_EL.log.value += `${value}\n`;
133+
}
136134
}
137135

138136
// ----------------------------------------------------
@@ -151,9 +149,12 @@ export function exampleApp () {
151149
}); */
152150

153151
function onButtonStart () {
154-
REC_START_BUTTON.disabled = true;
152+
FORM_EL.startButton.disabled = true;
153+
FORM_EL.stopButton.disabled = false;
154+
FORM_EL.stopButton.focus();
155+
/* REC_START_BUTTON.disabled = true;
155156
REC_STOP_BUTTON.disabled = false;
156-
REC_STOP_BUTTON.focus();
157+
REC_STOP_BUTTON.focus(); */
157158
}
158159

159160
function onRecognitionStart () {
@@ -162,9 +163,12 @@ function onRecognitionStart () {
162163
}
163164

164165
function onRecognitionStop () {
165-
REC_STOP_BUTTON.disabled = true;
166+
FORM_EL.stopButton.disabled = true;
167+
FORM_EL.startButton.disbled = false;
168+
FORM_EL.startButton.focus();
169+
/* REC_STOP_BUTTON.disabled = true;
166170
REC_START_BUTTON.disabled = false;
167-
REC_START_BUTTON.focus();
171+
REC_START_BUTTON.focus(); */
168172

169173
document.body.classList.add('recognizer-stopped');
170174
document.body.classList.remove('recognizer-started');

demo/style.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,22 @@ label {
2323
}
2424

2525
#actions,
26+
output,
2627
pre,
2728
textarea {
2829
background: var(--pale-grey);
2930
border: 1px solid var(--border-grey);
3031
border-radius: .25rem;
32+
display: inline-block;
3133
font-size: small;
32-
margin: 1.5rem 0;
34+
margin: .5rem 0 1.5rem;
35+
min-height: 1rem;
3336
padding: .5rem;
37+
width: 100%;
3438
}
3539

36-
textarea {
40+
output,
41+
.X_textarea {
3742
font: large/1.5 sans-serif;
3843
margin: 0;
3944
width: 98%;

index.html

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,65 @@
1111

1212
<h1> Adaptive speech recognition </h1>
1313

14-
<p id="sdk-version"></p>
14+
<form id="exampleAppForm">
1515

1616
<p>
17-
<button id="recognizer-start-button">Start dictation</button>
18-
<button id="recognizer-stop-button" disabled >Stop</button>
19-
<i id="recognizer-status" title="Recognizer stopped"></i>
17+
<input id="sdk-version" name="sdkVersion" readonly aria-label="SDK Version">
2018
</p>
2119

20+
<p>
21+
<button type="submit" id="startButton">Start dictation</button>
22+
<button type="reset" id="stopButton" disabled >Stop</button>
23+
<i id="recognizer-status" title="Recognizer stopped"></i>
24+
</p>
2225

2326
<p>
2427
<label for="result">Result</label>
25-
<textarea id="result" class="output" placeholder="(No result)" rows="2" readonly ></textarea>
28+
<output id="result" class="output" placeholder="(No result)"></output>
2629
</p>
2730

2831
<p id="actions" title="(actions)"></p>
2932

30-
<pre id="log" title="(log)">-
31-
</pre>
32-
33-
<pre id="options"></pre>
33+
<p>
34+
<label for="log">Log</label>
35+
<textarea id="log" readonly></textarea>
36+
</p>
37+
<p>
38+
<label for="options">Options</label>
39+
<textarea id="options" readonly></textarea>
40+
</p>
3441

42+
</form>
3543

3644
<a class="github-fork-ribbon" href="https://github.com/nfreear/dictation" data-ribbon="Fork me on GitHub" title="Fork 'nfreear/dictation' on GitHub">Fork nfreear/dictation on GitHub</a>
3745

38-
39-
<script
40-
data-X-src="https://cdn.jsdelivr.net/npm/[email protected]/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle-min.js"
41-
crossorigin="anonymous"
42-
></script>
43-
4446
<script type="importmap">
4547
{
4648
"imports": {
4749
"adaptive-speech-recog": "./index.js",
4850
"patient-speech-recog": "./index.js",
51+
"exampleApp": "./demo/lib/example-app.js",
4952
"web-speech-recog": "./src/web-api-speech-recog.js",
5053
"ms-cog-speech-sdk.v1.15.1": "https://cdn.jsdelivr.net/npm/[email protected]/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle-min.js",
51-
"ms-cog-speech-sdk": "https://unpkg.com/microsoft-cognitiveservices-speech-sdk@1.34.0/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle-min.js"
54+
"ms-cognitive-speech-sdk": "https://unpkg.com/microsoft-cognitiveservices-speech-sdk@1.43.1/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle-min.js"
5255
}
5356
}
5457
</script>
5558

56-
<script type="module" src="./demo/lib/example-app.js"></script>
57-
59+
<script type="module">
60+
import exampleApp from 'exampleApp';
61+
exampleApp();
62+
</script>
5863

5964
<!-- ====================================================== -->
6065

6166
<footer>
62-
© 2020 Nick Freear. All rights reserved.
67+
© 2025 Nick Freear. All rights reserved.
6368
<a href="https://github.com/nfreear/dictation">source</a>
6469
</footer>
6570

6671

67-
<pre class="hide">
72+
<pre hidden>
6873

6974
NDF, 08-Oct-2020.
7075

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
{
2-
"private": true,
32
"name": "adaptive-speech-recognizer",
4-
"version": "2.0.0-beta",
3+
"version": "2.1.0",
54
"description": "Adaptive dictation-mode speech recognizer ponyfill compatible with WebChat that gives the user time to think and stutter/stammer.",
65
"license": "MIT",
76
"repository": "https://github.com/nfreear/dictation.git",
87
"author": "Nick Freear",
9-
"main": "./index.js",
10-
"browser": "./index.js",
8+
"main": "index.js",
9+
"exports": {
10+
".": "./index.js",
11+
"./example-app": "./demo/lib/example-app.js",
12+
"./webApiSpeechRecog": "./src/web-api-speech-recog.js"
13+
},
1114
"type": "module",
1215
"scripts": {
16+
"build:site": "cp -R *.js src demo _site",
1317
"_": "# http://localhost:8080?key=_YOUR_AZURE_SPEECH_SUBSCRIPTION_KEY&actions=true",
1418
"start": "npm run _ && servor",
1519
"ts": "npx -p typescript tsc src/**/*.js --declaration --allowJs --emitDeclarationOnly --outDir types",
@@ -21,14 +25,14 @@
2125
"servor": "^4.0.2"
2226
},
2327
"peerDependencies": {
24-
"microsoft-cognitiveservices-speech-sdk": "^1.34.0",
28+
"microsoft-cognitiveservices-speech-sdk": "^1.43.1",
2529
"web-speech-cognitive-services": "^7.1.3",
2630
"react-dictate-button": "^2.0.1"
2731
},
2832
"CDN_peerDependencies": {
2933
"botframework-webchat-root": "^4.10.1",
3034
"sdk:1.15.1": "https://cdn.jsdelivr.net/npm/[email protected]/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle-min.js",
31-
"sdk": "https://unpkg.com/microsoft-cognitiveservices-speech-sdk@1.34.0/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle-min.js"
35+
"sdk": "https://unpkg.com/microsoft-cognitiveservices-speech-sdk@1.43.1/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle-min.js"
3236
},
3337
"keywords": [
3438
"microsoft",

src/SpeechSDK.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/**
2-
* @version 1.34.0
2+
* Export `SpeechSDK` globals.
3+
* @see https://www.npmjs.com/package/microsoft-cognitiveservices-speech-sdk
34
*/
4-
5-
import 'https://unpkg.com/[email protected]/distrib/browser/microsoft.cognitiveservices.speech.sdk.bundle-min.js';
6-
// import 'ms-cognitive-speech-sdk';
5+
import 'ms-cognitive-speech-sdk';
76

87
const {
98
AudioConfig, MicAudioSource,

0 commit comments

Comments
 (0)