@npcify/vue 0.2.1 → 0.4.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/README.md CHANGED
@@ -64,8 +64,14 @@ const reply = async (label) => {
64
64
  ## Component API
65
65
 
66
66
  - `options`: `baseUrl`, `characterId`, `apiKey`, `serverRendering`, and optional
67
- `assetProfile` (`original` or `web-optimized-v1`). See Export → Web SDK for the
68
- character's configuration. These are JavaScript props, never HTML attributes.
67
+ `assetProfile` (`original` or `web-optimized-v1`) and `inputModes` (`'options'`,
68
+ `'text'`, `'voice'`; `'voice'` needs the character's voice input, which the
69
+ owner turns on in the STT tab). See Export → Web SDK for the character's
70
+ configuration.
71
+ These are JavaScript props, never HTML attributes.
72
+ - Voice input: call `bindPushToTalk({ element })` on the ready SDK to talk while
73
+ the player holds a button or Space; the release sends the speech. See the
74
+ `@npcify/web` README (Voice input and input modes).
69
75
  - `@ready="handler"` and `@error="handler"` events expose the SDK and errors.
70
76
  - `class`/`style` (React: `className`/`style`) customize the outer div. It defaults
71
77
  to 100% width and 480px height. Give it a nonzero height.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as vue from 'vue';
2
2
  import { PropType } from 'vue';
3
3
  import { MountNpcifyOptions, Npcify } from '@npcify/web';
4
- export { Character, CharacterAnimation, CharacterAnimationPlayOptions, CharacterAudio, CharacterDisposeOptions, CharacterExpressions, CharacterOptions, CharacterShadowOptions, CharacterSpeechState, CharacterTransformOptions, LoadCharacterOptions, Npcify, NpcifyCharacter, NpcifyView, createCharacter, loadCharacter } from '@npcify/web';
4
+ export { Character, CharacterAnimation, CharacterAnimationPlayOptions, CharacterAudio, CharacterDisposeOptions, CharacterExpressions, CharacterOptions, CharacterShadowOptions, CharacterSpeechState, CharacterTransformOptions, InputMode, InputModeError, ListeningOptions, ListeningState, LoadCharacterOptions, Npcify, NpcifyCharacter, NpcifyView, PushToTalkOptions, SpeechInputError, SpeechInputResult, TranscriptEvent, bindPushToTalk, createCharacter, loadCharacter } from '@npcify/web';
5
5
 
6
6
  type NpcifyOptions = Omit<MountNpcifyOptions, 'canvas' | 'onError'>;
7
7
 
package/dist/index.js CHANGED
@@ -48,7 +48,10 @@ import {
48
48
  Npcify,
49
49
  NpcifyCharacter,
50
50
  createCharacter,
51
- loadCharacter
51
+ loadCharacter,
52
+ InputModeError,
53
+ SpeechInputError,
54
+ bindPushToTalk
52
55
  } from "@npcify/web";
53
56
  var NpcifyCanvas = defineComponent({
54
57
  name: "NpcifyCanvas",
@@ -70,7 +73,8 @@ var NpcifyCanvas = defineComponent({
70
73
  () => props.options.characterId,
71
74
  () => props.options.apiKey,
72
75
  () => props.options.serverRendering,
73
- () => props.options.assetProfile
76
+ () => props.options.assetProfile,
77
+ () => props.options.inputModes?.join(",")
74
78
  ],
75
79
  () => {
76
80
  cleanup?.();
@@ -98,9 +102,12 @@ var NpcifyCanvas = defineComponent({
98
102
  });
99
103
  export {
100
104
  Character,
105
+ InputModeError,
101
106
  Npcify,
102
107
  NpcifyCanvas,
103
108
  NpcifyCharacter,
109
+ SpeechInputError,
110
+ bindPushToTalk,
104
111
  createCharacter,
105
112
  loadCharacter
106
113
  };
package/examples/App.vue CHANGED
@@ -7,11 +7,14 @@
7
7
  {{ option.label }}
8
8
  </button>
9
9
  </div>
10
+ <button v-show="voice" ref="talk" type="button" :disabled="replies.length === 0">
11
+ {{ listening === 'idle' ? 'Hold to talk' : listening === 'recognizing' ? 'Recognizing…' : 'Listening…' }}
12
+ </button>
10
13
  <p role="status">{{ status }}</p>
11
14
  </template>
12
15
 
13
16
  <script setup>
14
- import { ref, shallowRef } from 'vue'
17
+ import { onBeforeUnmount, ref, shallowRef } from 'vue'
15
18
  import { NpcifyCanvas } from '@npcify/vue'
16
19
 
17
20
  const config = {
@@ -21,13 +24,30 @@ const config = {
21
24
  serverRendering: false,
22
25
  }
23
26
  const npcify = shallowRef(null)
27
+ const talk = ref(null)
24
28
  const started = ref(false)
25
29
  const replies = ref([])
30
+ const voice = ref(false)
31
+ const listening = ref('idle')
26
32
  const status = ref('')
33
+ let unbindTalk = () => {}
27
34
  const reportError = (error) => { status.value = error.message }
28
35
  const handleReady = (client) => {
29
36
  npcify.value = client
30
37
  client.onOptionsReady(({ options }) => { replies.value = options })
38
+ // Hold the button, or Space, to talk. The release sends the speech. Voice
39
+ // needs the character's voice input (its owner turns it on in the STT tab).
40
+ voice.value = client.inputModes.includes('voice')
41
+ client.onListeningState((state) => { listening.value = state })
42
+ client.onTranscript(({ text }) => { status.value = text })
43
+ if (voice.value) {
44
+ unbindTalk = client.bindPushToTalk({
45
+ element: talk.value,
46
+ enabled: () => replies.value.length > 0,
47
+ onResult: ({ sent }) => { if (sent) replies.value = [] },
48
+ onError: reportError,
49
+ })
50
+ }
31
51
  }
32
52
  const start = async () => {
33
53
  started.value = true
@@ -45,4 +65,5 @@ const reply = async (label) => {
45
65
  try { await npcify.value.sendMessage(label) }
46
66
  catch (error) { reportError(error) }
47
67
  }
68
+ onBeforeUnmount(() => unbindTalk())
48
69
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@npcify/vue",
3
- "version": "0.2.1",
3
+ "version": "0.4.0",
4
4
  "description": "Vue components for Npcify characters and conversations",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -23,7 +23,7 @@
23
23
  "registry": "https://registry.npmjs.org/"
24
24
  },
25
25
  "dependencies": {
26
- "@npcify/web": "^0.2.1"
26
+ "@npcify/web": "^0.4.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "vue": "^3.5.0"