@adminide-stack/yantra-mobile 12.0.157 → 12.0.159-alpha.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/lib/features/dictate/DictateExperience.js +97 -25
- package/lib/features/dictate/DictateExperience.js.map +1 -1
- package/lib/features/dictate/components/NoteChat.js +59 -21
- package/lib/features/dictate/components/NoteChat.js.map +1 -1
- package/lib/features/dictate/components/NoteView.js +32 -3
- package/lib/features/dictate/components/NoteView.js.map +1 -1
- package/lib/features/dictate/components/RecordPanel.js +66 -2
- package/lib/features/dictate/components/RecordPanel.js.map +1 -1
- package/lib/features/dictate/dictateClient.js +22 -1
- package/lib/features/dictate/dictateClient.js.map +1 -1
- package/lib/features/dictate/dictatePreference.js +25 -1
- package/lib/features/dictate/dictatePreference.js.map +1 -1
- package/lib/features/dictate/dictateVoice.js +34 -0
- package/lib/features/dictate/dictateVoice.js.map +1 -0
- package/lib/features/dictate/micInput.js +38 -0
- package/lib/features/dictate/micInput.js.map +1 -0
- package/lib/features/dictate/readAloud.js +141 -0
- package/lib/features/dictate/readAloud.js.map +1 -0
- package/lib/features/dictate/speechText.js +66 -0
- package/lib/features/dictate/speechText.js.map +1 -0
- package/lib/features/dictate/useDictationRecorder.js +75 -4
- package/lib/features/dictate/useDictationRecorder.js.map +1 -1
- package/lib/features/dictate/useVoiceQuestion.js +100 -0
- package/lib/features/dictate/useVoiceQuestion.js.map +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecordPanel.js","sources":["../../../../src/features/dictate/components/RecordPanel.tsx"],"sourcesContent":["/**\n * The microphone: one large button to start, then a timer, a live level,\n * Pause/Resume, Discard and Done. A pause the app made (it left the screen,\n * a call took the microphone, or the hour ran out) says why, and so does a\n * microphone that hears nothing, so no audio goes missing unnoticed.\n */\nimport React, { useEffect, useRef, useState } from 'react';\nimport { ActivityIndicator, StyleSheet, Text, View } from 'react-native';\nimport { MaterialCommunityIcons } from '@expo/vector-icons';\nimport { DIM, Tap } from '../../inbox/components/Tap';\nimport { formatDuration } from '../noteText';\nimport type { DictateTheme } from '../dictateTheme';\nimport type { PauseReason, RecorderPhase } from '../useDictationRecorder';\n\nconst BARS = 32;\n\n/** The last few seconds of level, as bars: the clinician can see the phone hears them. */\nfunction LevelBars({ level, active, theme }: { level: number; active: boolean; theme: DictateTheme }) {\n const [history, setHistory] = useState<number[]>(() => Array(BARS).fill(0));\n const levelRef = useRef(level);\n levelRef.current = level;\n useEffect(() => {\n if (!active) return;\n const id = setInterval(() => setHistory((h) => [...h.slice(1), levelRef.current]), 90);\n return () => clearInterval(id);\n }, [active]);\n return (\n <View style={styles.bars} accessibilityLabel=\"Microphone level\">\n {history.map((v, i) => (\n <View\n key={i}\n style={[\n styles.bar,\n {\n height: 6 + Math.round(v * 46),\n backgroundColor: active ? theme.rec : theme.border,\n opacity: active ? 0.35 + 0.65 * (i / BARS) : 1,\n },\n ]}\n />\n ))}\n </View>\n );\n}\n\nexport function StartPanel({\n theme,\n starting,\n recordsInBackground,\n onStart,\n}: {\n theme: DictateTheme;\n starting: boolean;\n /** This app keeps recording with the phone locked or another app open. */\n recordsInBackground: boolean;\n onStart: () => void;\n}) {\n // One target for the button and its words: \"Start dictating\" reads like the thing to tap.\n return (\n <Tap\n onPress={onStart}\n disabled={starting}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Start dictating\"\n style={styles.start}\n pressedStyle={DIM}\n >\n <View style={[styles.micButton, { backgroundColor: theme.accent, shadowColor: theme.accent }]}>\n {starting ? (\n <ActivityIndicator color={theme.accentInk} />\n ) : (\n <MaterialCommunityIcons name=\"microphone\" size={42} color={theme.accentInk} />\n )}\n </View>\n <Text style={[styles.startLabel, { color: theme.ink }]}>Start dictating</Text>\n <Text style={[styles.startHint, { color: theme.muted }]}>\n {recordsInBackground\n ? 'Keeps recording if you lock the phone or switch apps.'\n : 'Keep Yantra open while you speak.'}\n </Text>\n </Tap>\n );\n}\n\ntype Notice = { icon: 'pause-circle-outline' | 'microphone-off'; text: string };\n\n/** Why the recording is not taking down the visit right now, if it is not. */\nfunction recordingNotice(pauseReason: PauseReason, noInput: boolean): Notice | null {\n if (pauseReason === 'background') {\n return {\n icon: 'pause-circle-outline',\n text: 'Paused because Yantra left the screen. Resume to keep dictating.',\n };\n }\n if (pauseReason === 'interrupted') {\n return {\n icon: 'pause-circle-outline',\n text: 'Paused for a call or another app using the microphone. Resume to keep dictating.',\n };\n }\n if (pauseReason === 'limit') {\n return {\n icon: 'pause-circle-outline',\n text: 'An hour is the most one dictation holds. Tap Done to write the note.',\n };\n }\n if (noInput) {\n return {\n icon: 'microphone-off',\n text: 'No sound is reaching the microphone. Check that nothing covers it and no other app is using it.',\n };\n }\n return null;\n}\n\nexport function RecordingPanel({\n theme,\n phase,\n pauseReason,\n elapsedMs,\n level,\n noInput,\n onPause,\n onResume,\n onDone,\n onDiscard,\n}: {\n theme: DictateTheme;\n phase: Exclude<RecorderPhase, 'idle'>;\n pauseReason: PauseReason;\n elapsedMs: number;\n level: number;\n /** The microphone has carried no signal for a few seconds of recording. */\n noInput: boolean;\n onPause: () => void;\n onResume: () => void;\n onDone: () => void;\n onDiscard: () => void;\n}) {\n const live = phase === 'recording';\n const notice = recordingNotice(pauseReason, live && noInput);\n return (\n <View style={styles.recording}>\n <View style={[styles.status, { backgroundColor: live ? theme.recSoft : theme.chip }]}>\n <View style={[styles.dot, { backgroundColor: live ? theme.rec : theme.faint }]} />\n <Text style={[styles.statusText, { color: live ? theme.rec : theme.muted }]}>\n {live ? 'Recording' : 'Paused'}\n </Text>\n </View>\n <Text\n style={[styles.timer, { color: theme.ink }]}\n accessibilityLabel={`Elapsed ${formatDuration(elapsedMs)}`}\n >\n {formatDuration(elapsedMs)}\n </Text>\n <LevelBars level={level} active={live} theme={theme} />\n {notice ? (\n <View style={[styles.notice, { backgroundColor: theme.warnSoft, borderColor: theme.warnBorder }]}>\n <MaterialCommunityIcons name={notice.icon} size={18} color={theme.warnInk} />\n <Text style={[styles.noticeText, { color: theme.warnInk }]}>{notice.text}</Text>\n </View>\n ) : null}\n <View style={styles.controls}>\n <Tap\n onPress={onDiscard}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Discard this dictation\"\n style={[styles.side, { backgroundColor: theme.chip }]}\n pressedStyle={DIM}\n >\n <MaterialCommunityIcons name=\"trash-can-outline\" size={24} color={theme.muted} />\n </Tap>\n <Tap\n onPress={live ? onPause : onResume}\n disabled={pauseReason === 'limit'}\n accessibilityRole=\"button\"\n accessibilityLabel={live ? 'Pause' : 'Resume'}\n style={[\n styles.main,\n {\n backgroundColor: live ? theme.rec : theme.accent,\n opacity: pauseReason === 'limit' ? 0.4 : 1,\n },\n ]}\n pressedStyle={DIM}\n >\n <MaterialCommunityIcons name={live ? 'pause' : 'microphone'} size={34} color=\"#ffffff\" />\n </Tap>\n <Tap\n onPress={onDone}\n disabled={elapsedMs < 1000}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Done, write the note\"\n style={[styles.side, { backgroundColor: theme.accentSoft, opacity: elapsedMs < 1000 ? 0.4 : 1 }]}\n pressedStyle={DIM}\n >\n <MaterialCommunityIcons name=\"check\" size={26} color={theme.accent} />\n </Tap>\n </View>\n <View style={styles.legend}>\n <Text style={[styles.legendText, { color: theme.faint }]}>Discard</Text>\n <Text style={[styles.legendText, { color: theme.faint }]}>{live ? 'Pause' : 'Resume'}</Text>\n <Text style={[styles.legendText, { color: theme.faint }]}>Done</Text>\n </View>\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n start: { alignItems: 'center', paddingVertical: 28 },\n micButton: {\n width: 104,\n height: 104,\n borderRadius: 52,\n alignItems: 'center',\n justifyContent: 'center',\n shadowOpacity: 0.28,\n shadowRadius: 16,\n shadowOffset: { width: 0, height: 8 },\n elevation: 6,\n },\n startLabel: { marginTop: 18, fontSize: 17, fontWeight: '600' },\n startHint: { marginTop: 6, fontSize: 13 },\n recording: { alignItems: 'center', paddingTop: 12, paddingBottom: 8 },\n status: {\n flexDirection: 'row',\n alignItems: 'center',\n paddingHorizontal: 12,\n paddingVertical: 6,\n borderRadius: 999,\n },\n dot: { width: 8, height: 8, borderRadius: 4, marginRight: 8 },\n statusText: { fontSize: 13, fontWeight: '600' },\n timer: { marginTop: 18, fontSize: 56, fontWeight: '300', fontVariant: ['tabular-nums'], letterSpacing: 1 },\n bars: { marginTop: 18, height: 56, flexDirection: 'row', alignItems: 'center', gap: 3 },\n bar: { width: 4, borderRadius: 2 },\n notice: {\n marginTop: 18,\n marginHorizontal: 8,\n flexDirection: 'row',\n alignItems: 'center',\n gap: 8,\n paddingHorizontal: 12,\n paddingVertical: 10,\n borderRadius: 12,\n borderWidth: StyleSheet.hairlineWidth,\n },\n noticeText: { flex: 1, fontSize: 13, lineHeight: 18 },\n controls: { marginTop: 28, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 36 },\n side: { width: 56, height: 56, borderRadius: 28, alignItems: 'center', justifyContent: 'center' },\n main: { width: 80, height: 80, borderRadius: 40, alignItems: 'center', justifyContent: 'center' },\n legend: { marginTop: 8, flexDirection: 'row', justifyContent: 'center', gap: 36 },\n legendText: { width: 68, textAlign: 'center', fontSize: 12 },\n});\n"],"names":[],"mappings":"iTAaA,MAAM,IAAO,GAAA,EAAA;AAGb,SAAS,SAAU,CAAA;AAAA,EACjB,KAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAIG,EAAA;AACD,EAAM,MAAA,CAAC,OAAS,EAAA,UAAU,CAAI,GAAA,QAAA,CAAmB,MAAM,KAAA,CAAM,IAAI,CAAA,CAAE,IAAK,CAAA,CAAC,CAAC,CAAA;AAC1E,EAAM,MAAA,QAAA,GAAW,OAAO,KAAK,CAAA;AAC7B,EAAA,QAAA,CAAS,OAAU,GAAA,KAAA;AACnB,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,MAAQ,EAAA;AACb,IAAA,MAAM,EAAK,GAAA,WAAA,CAAY,MAAM,U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AY,EAAA,QAAA;AAAA,IACZ,cAAgB,EAAA,QAAA;AAAA,IAChB,GAAK,EAAA;AAAA,GACP;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,KAAO,EAAA,EAAA;AAAA,IACP,MAAQ,EAAA,EAAA;AAAA,IACR,YAAc,EAAA,EAAA;AAAA,IACd,UAAY,EAAA,QAAA;AAAA,IACZ,cAAgB,EAAA;AAAA,GAClB;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,KAAO,EAAA,EAAA;AAAA,IACP,MAAQ,EAAA,EAAA;AAAA,IACR,YAAc,EAAA,EAAA;AAAA,IACd,UAAY,EAAA,QAAA;AAAA,IACZ,cAAgB,EAAA;AAAA,GAClB;AAAA,EACA,MAAQ,EAAA;AAAA,IACN,SAAW,EAAA,CAAA;AAAA,IACX,aAAe,EAAA,KAAA;AAAA,IACf,cAAgB,EAAA,QAAA;AAAA,IAChB,GAAK,EAAA;AAAA,GACP;AAAA,EACA,UAAY,EAAA;AAAA,IACV,KAAO,EAAA,EAAA;AAAA,IACP,SAAW,EAAA,QAAA;AAAA,IACX,QAAU,EAAA;AAAA;AAEd,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"RecordPanel.js","sources":["../../../../src/features/dictate/components/RecordPanel.tsx"],"sourcesContent":["/**\n * The microphone: one large button to start, then a timer, a live level,\n * which microphone is listening (AirPods, or the phone's) with the switch to\n * the other, Pause/Resume, Discard and Done. A pause the app made (it left the\n * screen, a call took the microphone, or the hour ran out) says why, and so do\n * a microphone that hears nothing and a headset that went away, so no audio\n * goes missing unnoticed.\n */\nimport React, { useEffect, useRef, useState } from 'react';\nimport { ActivityIndicator, StyleSheet, Text, View } from 'react-native';\nimport { MaterialCommunityIcons } from '@expo/vector-icons';\nimport { DIM, Tap } from '../../inbox/components/Tap';\nimport type { Mic } from '../micInput';\nimport { formatDuration } from '../noteText';\nimport type { DictateTheme } from '../dictateTheme';\nimport type { PauseReason, RecorderPhase } from '../useDictationRecorder';\n\nconst BARS = 32;\n\n/** The last few seconds of level, as bars: the clinician can see the phone hears them. */\nfunction LevelBars({ level, active, theme }: { level: number; active: boolean; theme: DictateTheme }) {\n const [history, setHistory] = useState<number[]>(() => Array(BARS).fill(0));\n const levelRef = useRef(level);\n levelRef.current = level;\n useEffect(() => {\n if (!active) return;\n const id = setInterval(() => setHistory((h) => [...h.slice(1), levelRef.current]), 90);\n return () => clearInterval(id);\n }, [active]);\n return (\n <View style={styles.bars} accessibilityLabel=\"Microphone level\">\n {history.map((v, i) => (\n <View\n key={i}\n style={[\n styles.bar,\n {\n height: 6 + Math.round(v * 46),\n backgroundColor: active ? theme.rec : theme.border,\n opacity: active ? 0.35 + 0.65 * (i / BARS) : 1,\n },\n ]}\n />\n ))}\n </View>\n );\n}\n\nexport function StartPanel({\n theme,\n starting,\n recordsInBackground,\n onStart,\n}: {\n theme: DictateTheme;\n starting: boolean;\n /** This app keeps recording with the phone locked or another app open. */\n recordsInBackground: boolean;\n onStart: () => void;\n}) {\n // One target for the button and its words: \"Start dictating\" reads like the thing to tap.\n return (\n <Tap\n onPress={onStart}\n disabled={starting}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Start dictating\"\n style={styles.start}\n pressedStyle={DIM}\n >\n <View style={[styles.micButton, { backgroundColor: theme.accent, shadowColor: theme.accent }]}>\n {starting ? (\n <ActivityIndicator color={theme.accentInk} />\n ) : (\n <MaterialCommunityIcons name=\"microphone\" size={42} color={theme.accentInk} />\n )}\n </View>\n <Text style={[styles.startLabel, { color: theme.ink }]}>Start dictating</Text>\n <Text style={[styles.startHint, { color: theme.muted }]}>\n {recordsInBackground\n ? 'Keeps recording if you lock the phone or switch apps.'\n : 'Keep Yantra open while you speak.'}\n </Text>\n </Tap>\n );\n}\n\ntype Notice = { icon: 'pause-circle-outline' | 'microphone-off' | 'headphones-off'; text: string };\n\n/** Why the recording is not taking down the dictation right now, or not the way it was. */\nfunction recordingNotice(\n pauseReason: PauseReason,\n noInput: boolean,\n micLost: string | null,\n mic: Mic | null,\n): Notice | null {\n if (pauseReason === 'background') {\n return {\n icon: 'pause-circle-outline',\n text: 'Paused because Yantra left the screen. Resume to keep dictating.',\n };\n }\n if (pauseReason === 'interrupted') {\n return {\n icon: 'pause-circle-outline',\n text: 'Paused for a call or another app using the microphone. Resume to keep dictating.',\n };\n }\n if (pauseReason === 'limit') {\n return {\n icon: 'pause-circle-outline',\n text: 'An hour is the most one dictation holds. Tap Done to write the note.',\n };\n }\n if (micLost && mic) {\n return {\n icon: 'headphones-off',\n text: `${micLost} disconnected. Still recording with the ${mic.label}.`,\n };\n }\n if (noInput) {\n return {\n icon: 'microphone-off',\n text: 'No sound is reaching the microphone. Check that nothing covers it and no other app is using it.',\n };\n }\n return null;\n}\n\nexport function RecordingPanel({\n theme,\n phase,\n pauseReason,\n elapsedMs,\n level,\n noInput,\n mic = null,\n otherMic = null,\n micLost = null,\n onSwitchMic,\n onPause,\n onResume,\n onDone,\n onDiscard,\n}: {\n theme: DictateTheme;\n phase: Exclude<RecorderPhase, 'idle'>;\n pauseReason: PauseReason;\n elapsedMs: number;\n level: number;\n /** The microphone has carried no signal for a few seconds of recording. */\n noInput: boolean;\n /** The microphone listening (null on a binary that cannot say). */\n mic?: Mic | null;\n /** The other microphone connected, to switch to. */\n otherMic?: Mic | null;\n /** The headset that went away mid-dictation. */\n micLost?: string | null;\n onSwitchMic?: () => void;\n onPause: () => void;\n onResume: () => void;\n onDone: () => void;\n onDiscard: () => void;\n}) {\n const live = phase === 'recording';\n const notice = recordingNotice(pauseReason, live && noInput, live ? micLost : null, mic);\n return (\n <View style={styles.recording}>\n <View style={[styles.status, { backgroundColor: live ? theme.recSoft : theme.chip }]}>\n <View style={[styles.dot, { backgroundColor: live ? theme.rec : theme.faint }]} />\n <Text style={[styles.statusText, { color: live ? theme.rec : theme.muted }]}>\n {live ? 'Recording' : 'Paused'}\n </Text>\n </View>\n <Text\n style={[styles.timer, { color: theme.ink }]}\n accessibilityLabel={`Elapsed ${formatDuration(elapsedMs)}`}\n >\n {formatDuration(elapsedMs)}\n </Text>\n <LevelBars level={level} active={live} theme={theme} />\n {mic ? (\n <View style={styles.micRow}>\n <MaterialCommunityIcons\n name={mic.kind === 'headset' ? 'headphones' : 'cellphone'}\n size={16}\n color={theme.muted}\n />\n <Text\n numberOfLines={1}\n style={[styles.micText, { color: theme.muted }]}\n accessibilityLabel={`Listening with ${mic.label}`}\n >\n {mic.label}\n </Text>\n {otherMic && onSwitchMic ? (\n <Tap\n onPress={onSwitchMic}\n accessibilityRole=\"button\"\n accessibilityLabel={`Use ${otherMic.label}`}\n style={[styles.micSwitch, { borderColor: theme.border, backgroundColor: theme.card }]}\n pressedStyle={DIM}\n >\n <Text numberOfLines={1} style={[styles.micSwitchText, { color: theme.accent }]}>\n Use {otherMic.label}\n </Text>\n </Tap>\n ) : null}\n </View>\n ) : null}\n {mic?.kind === 'headset' && otherMic ? (\n <Text style={[styles.micHint, { color: theme.faint }]}>\n Best for your own voice. For a class or a meeting, use the {otherMic.label}.\n </Text>\n ) : null}\n {notice ? (\n <View style={[styles.notice, { backgroundColor: theme.warnSoft, borderColor: theme.warnBorder }]}>\n <MaterialCommunityIcons name={notice.icon} size={18} color={theme.warnInk} />\n <Text style={[styles.noticeText, { color: theme.warnInk }]}>{notice.text}</Text>\n </View>\n ) : null}\n <View style={styles.controls}>\n <Tap\n onPress={onDiscard}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Discard this dictation\"\n style={[styles.side, { backgroundColor: theme.chip }]}\n pressedStyle={DIM}\n >\n <MaterialCommunityIcons name=\"trash-can-outline\" size={24} color={theme.muted} />\n </Tap>\n <Tap\n onPress={live ? onPause : onResume}\n disabled={pauseReason === 'limit'}\n accessibilityRole=\"button\"\n accessibilityLabel={live ? 'Pause' : 'Resume'}\n style={[\n styles.main,\n {\n backgroundColor: live ? theme.rec : theme.accent,\n opacity: pauseReason === 'limit' ? 0.4 : 1,\n },\n ]}\n pressedStyle={DIM}\n >\n <MaterialCommunityIcons name={live ? 'pause' : 'microphone'} size={34} color=\"#ffffff\" />\n </Tap>\n <Tap\n onPress={onDone}\n disabled={elapsedMs < 1000}\n accessibilityRole=\"button\"\n accessibilityLabel=\"Done, write the note\"\n style={[styles.side, { backgroundColor: theme.accentSoft, opacity: elapsedMs < 1000 ? 0.4 : 1 }]}\n pressedStyle={DIM}\n >\n <MaterialCommunityIcons name=\"check\" size={26} color={theme.accent} />\n </Tap>\n </View>\n <View style={styles.legend}>\n <Text style={[styles.legendText, { color: theme.faint }]}>Discard</Text>\n <Text style={[styles.legendText, { color: theme.faint }]}>{live ? 'Pause' : 'Resume'}</Text>\n <Text style={[styles.legendText, { color: theme.faint }]}>Done</Text>\n </View>\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n start: { alignItems: 'center', paddingVertical: 28 },\n micButton: {\n width: 104,\n height: 104,\n borderRadius: 52,\n alignItems: 'center',\n justifyContent: 'center',\n shadowOpacity: 0.28,\n shadowRadius: 16,\n shadowOffset: { width: 0, height: 8 },\n elevation: 6,\n },\n startLabel: { marginTop: 18, fontSize: 17, fontWeight: '600' },\n startHint: { marginTop: 6, fontSize: 13 },\n recording: { alignItems: 'center', paddingTop: 12, paddingBottom: 8 },\n status: {\n flexDirection: 'row',\n alignItems: 'center',\n paddingHorizontal: 12,\n paddingVertical: 6,\n borderRadius: 999,\n },\n dot: { width: 8, height: 8, borderRadius: 4, marginRight: 8 },\n statusText: { fontSize: 13, fontWeight: '600' },\n timer: { marginTop: 18, fontSize: 56, fontWeight: '300', fontVariant: ['tabular-nums'], letterSpacing: 1 },\n bars: { marginTop: 18, height: 56, flexDirection: 'row', alignItems: 'center', gap: 3 },\n bar: { width: 4, borderRadius: 2 },\n notice: {\n marginTop: 18,\n marginHorizontal: 8,\n flexDirection: 'row',\n alignItems: 'center',\n gap: 8,\n paddingHorizontal: 12,\n paddingVertical: 10,\n borderRadius: 12,\n borderWidth: StyleSheet.hairlineWidth,\n },\n noticeText: { flex: 1, fontSize: 13, lineHeight: 18 },\n micRow: {\n marginTop: 14,\n maxWidth: '100%',\n flexDirection: 'row',\n alignItems: 'center',\n gap: 6,\n paddingHorizontal: 8,\n },\n micText: { flexShrink: 1, fontSize: 13, fontWeight: '600' },\n micSwitch: {\n marginLeft: 6,\n flexShrink: 1,\n paddingHorizontal: 10,\n paddingVertical: 5,\n borderRadius: 999,\n borderWidth: StyleSheet.hairlineWidth,\n },\n micSwitchText: { fontSize: 13, fontWeight: '600' },\n micHint: { marginTop: 6, paddingHorizontal: 24, fontSize: 12, lineHeight: 17, textAlign: 'center' },\n controls: { marginTop: 28, flexDirection: 'row', alignItems: 'center', justifyContent: 'center', gap: 36 },\n side: { width: 56, height: 56, borderRadius: 28, alignItems: 'center', justifyContent: 'center' },\n main: { width: 80, height: 80, borderRadius: 40, alignItems: 'center', justifyContent: 'center' },\n legend: { marginTop: 8, flexDirection: 'row', justifyContent: 'center', gap: 36 },\n legendText: { width: 68, textAlign: 'center', fontSize: 12 },\n});\n"],"names":[],"mappings":"iTAgBA,MAAM,IAAO,GAAA,EAAA;AAGb,SAAS,SAAU,CAAA;AAAA,EACjB,KAAA;AAAA,EACA,MAAA;AAAA,EACA;AACF,CAIG,EAAA;AACD,EAAM,MAAA,CAAC,OAAS,EAAA,UAAU,CAAI,GAAA,QAAA,CAAmB,MAAM,KAAA,CAAM,IAAI,CAAA,CAAE,IAAK,CAAA,CAAC,CAAC,CAAA;AAC1E,EAAM,MAAA,QAAA,GAAW,OAAO,KAAK,CAAA;AAC7B,EAAA,QAAA,CAAS,OAAU,GAAA,KAAA;AACnB,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,MAAQ,EAAA;AACb,IAAA,MAAM,EAAK,GAAA,WAAA,CAAY,MAAM,UAAA,CAAW,OAAK,CAAC,GAAG,CAAE,CAAA,KAAA,CAAM,CAAC,CAAG,EAAA,QAAA,CAAS,OAAO,CAAC,GAAG,EAAE,CAAA;AACnF,IAAO,OAAA,MAAM,cAAc,EAAE,CA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cAAgB,EAAA,QAAA;AAAA,IAChB,GAAK,EAAA;AAAA,GACP;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,KAAO,EAAA,EAAA;AAAA,IACP,MAAQ,EAAA,EAAA;AAAA,IACR,YAAc,EAAA,EAAA;AAAA,IACd,UAAY,EAAA,QAAA;AAAA,IACZ,cAAgB,EAAA;AAAA,GAClB;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,KAAO,EAAA,EAAA;AAAA,IACP,MAAQ,EAAA,EAAA;AAAA,IACR,YAAc,EAAA,EAAA;AAAA,IACd,UAAY,EAAA,QAAA;AAAA,IACZ,cAAgB,EAAA;AAAA,GAClB;AAAA,EACA,MAAQ,EAAA;AAAA,IACN,SAAW,EAAA,CAAA;AAAA,IACX,aAAe,EAAA,KAAA;AAAA,IACf,cAAgB,EAAA,QAAA;AAAA,IAChB,GAAK,EAAA;AAAA,GACP;AAAA,EACA,UAAY,EAAA;AAAA,IACV,KAAO,EAAA,EAAA;AAAA,IACP,SAAW,EAAA,QAAA;AAAA,IACX,QAAU,EAAA;AAAA;AAEd,CAAC,CAAA"}
|
|
@@ -21,10 +21,12 @@ const DICTATE_CONNECTOR = "yantra-meetings";
|
|
|
21
21
|
const NOTE_ACTION = "YANTRA_MEETINGS_DICTATION_NOTE";
|
|
22
22
|
const SUGGEST_ACTION = "YANTRA_MEETINGS_DICTATION_SUGGEST";
|
|
23
23
|
const ASK_ACTION = "YANTRA_MEETINGS_DICTATION_ASK";
|
|
24
|
+
const SPEAK_ACTION = "YANTRA_MEETINGS_DICTATION_SPEAK";
|
|
24
25
|
const CLINICAL_NOTE_ACTION = "YANTRA_MEETINGS_CLINICAL_NOTE";
|
|
25
26
|
const CLINICAL_SUGGEST_ACTION = "YANTRA_MEETINGS_CLINICAL_SUGGEST";
|
|
26
27
|
const SUGGEST_TIMEOUT_MS = 4 * 6e4;
|
|
27
28
|
const ASK_TIMEOUT_MS = 3 * 6e4;
|
|
29
|
+
const SPEAK_TIMEOUT_MS = 6e4;
|
|
28
30
|
const NOTE_TIMEOUT_MS = 10 * 6e4;
|
|
29
31
|
const PARAMS_MAX_BYTES = 11e4;
|
|
30
32
|
class DictateError extends Error {
|
|
@@ -257,4 +259,23 @@ function askErrorText(err) {
|
|
|
257
259
|
if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\d\d/i.test(message)) return "Yantra could not answer right now. This is a problem on our side; try again in a few minutes.";
|
|
258
260
|
if (/timed? ?out|abort/i.test(message)) return "The answer took too long. Try again.";
|
|
259
261
|
return "No answer came back. Try again.";
|
|
260
|
-
}
|
|
262
|
+
}
|
|
263
|
+
async function speakText(text, identifiers, deps) {
|
|
264
|
+
const raw = await deps.exec(DICTATE_CONNECTOR, SPEAK_ACTION, {
|
|
265
|
+
text,
|
|
266
|
+
identifiers: tokensOf(identifiers)
|
|
267
|
+
}, {
|
|
268
|
+
timeoutMs: SPEAK_TIMEOUT_MS
|
|
269
|
+
});
|
|
270
|
+
const layer = findLayer(raw, (l) => typeof l.audio_base64 === "string", "No speech came back.");
|
|
271
|
+
const audio = str(layer.audio_base64);
|
|
272
|
+
if (!audio) throw new DictateError("failed", "No speech came back.");
|
|
273
|
+
return audio;
|
|
274
|
+
}
|
|
275
|
+
function readErrorText(err) {
|
|
276
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
277
|
+
if (/network request failed|offline|not signed in/i.test(message)) return "You are offline or signed out, so it cannot be read aloud. Try again when you are back online.";
|
|
278
|
+
if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message)) return "Reading aloud is not available on this workspace yet.";
|
|
279
|
+
if (/temporarily unavailable|problem on our side|HTTP 5\d\d/i.test(message)) return "Yantra could not read it aloud right now. This is a problem on our side; try again in a few minutes.";
|
|
280
|
+
return "It could not be read aloud. Try again.";
|
|
281
|
+
}export{ASK_ACTION,ASK_TIMEOUT_MS,CLINICAL_NOTE_ACTION,CLINICAL_SUGGEST_ACTION,DICTATE_CONNECTOR,DictateError,NOTE_ACTION,NOTE_TIMEOUT_MS,PARAMS_MAX_BYTES,SPEAK_ACTION,SPEAK_TIMEOUT_MS,SUGGEST_ACTION,SUGGEST_TIMEOUT_MS,askAboutNote,askErrorText,canRewrite,dictateErrorText,fitTranscript,identifiersOf,readErrorText,rewriteErrorText,rewriteNote,speakText,suggestErrorText,suggestFromNote,unwrapNote,writeNoteFromRecording};//# sourceMappingURL=dictateClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictateClient.js","sources":["../../../src/features/dictate/dictateClient.ts"],"sourcesContent":["/**\n * Recording -> notes that fit it. The recording is uploaded first and handed\n * to the connector as a URL (connector params travel as one CLI argument,\n * capped at 128 KB - audio never rides inline), then\n * YANTRA_MEETINGS_DICTATION_NOTE transcribes it, works out what it is (a\n * visit, a class, a meeting, an idea, a story...) and writes the note from a\n * transcript whose identifiers are placeholders; it returns the note both ways.\n *\n * Everything after that reads the hidden version only, so nothing identifying\n * goes back to the AI from this phone: the suggestions\n * (YANTRA_MEETINGS_DICTATION_SUGGEST), a rewrite as another kind (the note\n * action again, from the hidden transcript), and the chat about the note\n * (YANTRA_MEETINGS_DICTATION_ASK), whose messages have every name and number\n * the note knows swapped for its placeholder here first.\n *\n * A workspace whose connector predates the dictation actions still gets a\n * visit note and its suggestions from the clinical ones.\n */\nimport type { RemoteConnectorExec } from '../canvas/videoEditor/remoteMediaClient';\nimport { asRecord, noteIsEmpty, shapeNote, str, toClinical } from './noteShape';\nimport { hideKnown, knownIdentifiers } from './privacy';\nimport type {\n ChatTurn,\n DictationKind,\n DictationNote,\n DictationRecord,\n NoteIdentifier,\n NoteRedaction,\n NoteSuggestion,\n SuggestionKind,\n} from './types';\n\nexport const DICTATE_CONNECTOR = 'yantra-meetings';\nexport const NOTE_ACTION = 'YANTRA_MEETINGS_DICTATION_NOTE';\nexport const SUGGEST_ACTION = 'YANTRA_MEETINGS_DICTATION_SUGGEST';\nexport const ASK_ACTION = 'YANTRA_MEETINGS_DICTATION_ASK';\n/** What a connector from before the dictation actions offers: a visit note and its suggestions. */\nexport const CLINICAL_NOTE_ACTION = 'YANTRA_MEETINGS_CLINICAL_NOTE';\nexport const CLINICAL_SUGGEST_ACTION = 'YANTRA_MEETINGS_CLINICAL_SUGGEST';\n/** A read of one note runs about ten seconds. */\nexport const SUGGEST_TIMEOUT_MS = 4 * 60_000;\nexport const ASK_TIMEOUT_MS = 3 * 60_000;\n/** Transcription plus the note runs ~10 s for two minutes of speech; an hour's dictation stays well inside this. */\nexport const NOTE_TIMEOUT_MS = 10 * 60_000;\n/** Connector params ride as one CLI argument capped at 128 KB; what goes back to the AI stays under this. */\nexport const PARAMS_MAX_BYTES = 110_000;\n/** The earlier turns a chat message carries. */\nexport const CHAT_CONTEXT_TURNS = 16;\n\nexport type DictateStage = 'uploading' | 'writing';\n\nexport interface DictateDeps {\n exec: RemoteConnectorExec;\n upload: (localUri: string) => Promise<string>;\n}\n\nexport interface WrittenNote {\n note: DictationNote;\n transcript: string;\n model?: string;\n /** Absent from a connector that does not hide identifiers yet. */\n redaction?: NoteRedaction;\n}\n\nexport class DictateError extends Error {\n constructor(\n readonly kind: 'offline' | 'unavailable' | 'empty' | 'failed',\n message: string,\n ) {\n super(message);\n this.name = 'DictateError';\n }\n}\n\ntype Json = Record<string, unknown>;\nconst SUGGESTION_KINDS: SuggestionKind[] = ['missing', 'safety', 'coding', 'follow_up', 'check', 'question'];\n\n/** cdecli's words for an action this workspace's connector does not have (yet). */\nconst MISSING_ACTION = /action '[^']*' not found in connector/i;\n\n/** `action`, or on a connector that does not have it, `legacy` (when there is one). */\nasync function execOr(\n deps: Pick<DictateDeps, 'exec'>,\n action: string,\n params: Json,\n timeoutMs: number,\n legacy?: { action: string; params: Json },\n): Promise<unknown> {\n try {\n return await deps.exec(DICTATE_CONNECTOR, action, params, { timeoutMs });\n } catch (err) {\n if (!legacy || !MISSING_ACTION.test(err instanceof Error ? err.message : String(err))) throw err;\n return deps.exec(DICTATE_CONNECTOR, legacy.action, legacy.params, { timeoutMs });\n }\n}\n\n/** The first layer (the reply, its `data`, its `result`...) that `has` accepts; the connector's own error if none. */\nfunction findLayer(raw: unknown, has: (layer: Json) => boolean, empty: string): Json {\n let layer = asRecord(raw);\n const seen: Json[] = [];\n for (let depth = 0; layer && depth < 6; depth += 1) {\n if (has(layer)) return layer;\n seen.push(layer);\n layer = asRecord(layer.data) ?? asRecord(layer.result);\n }\n const reason = seen\n .flatMap((l) => [l.error, l.message, l.stderr])\n .find((v): v is string => typeof v === 'string' && v.trim().length > 0);\n throw new DictateError('failed', reason ?? empty);\n}\n\n/** UTF-8 bytes, over-counted for astral characters (which only makes the budget safer). */\nfunction utf8Bytes(text: string): number {\n let n = 0;\n for (let i = 0; i < text.length; i += 1) {\n const c = text.charCodeAt(i);\n if (c < 0x80) n += 1;\n else if (c < 0x800) n += 2;\n else n += 3;\n }\n return n;\n}\n\n/** The transcript cut (at the end) until the params carrying it fit one connector call. */\nexport function fitTranscript(rest: Json, transcript: string): string {\n const budget = PARAMS_MAX_BYTES - utf8Bytes(JSON.stringify(rest)) - 32;\n let fitted = transcript;\n while (fitted && utf8Bytes(JSON.stringify(fitted)) > budget)\n fitted = fitted.slice(0, Math.floor(fitted.length * 0.9));\n return fitted;\n}\n\n/** Only well-formed placeholders: a malformed one could not be put back. */\nexport function identifiersOf(v: unknown): NoteIdentifier[] {\n return (Array.isArray(v) ? v : [])\n .map(asRecord)\n .filter((i): i is Json => !!i && /^\\[[A-Z]+_\\d+\\]$/.test(str(i.token)) && !!str(i.value))\n .map((i) => ({ token: str(i.token), value: str(i.value), kind: str(i.kind) }));\n}\n\n/** Which placeholders exist, so a new one numbers on; never what they stand for. */\nconst tokensOf = (ids: NoteIdentifier[]) => ids.map(({ token, kind }) => ({ token, kind }));\n\nfunction redactionOf(v: unknown): NoteRedaction | undefined {\n const r = asRecord(v);\n const note = asRecord(r?.note);\n if (!r || !note) return undefined;\n return {\n method: r.method === 'patterns' ? 'patterns' : 'entities',\n note: shapeNote(note),\n transcript: str(r.transcript),\n identifiers: identifiersOf(r.identifiers),\n };\n}\n\n/** The note whatever wraps it ({ data: { note } }, { result: ... }), shaped defensively. */\nexport function unwrapNote(raw: unknown): WrittenNote {\n const layer = findLayer(raw, (l) => !!asRecord(l.note), 'The note came back empty.');\n const redaction = redactionOf(layer.redaction);\n return {\n note: shapeNote(asRecord(layer.note)!),\n transcript: str(asRecord(layer.transcript)?.text),\n model: str(layer.model) || undefined,\n ...(redaction ? { redaction } : {}),\n };\n}\n\n/** A message a person can act on, never a stack trace. */\nexport function dictateErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (err instanceof DictateError && err.kind === 'empty')\n return 'No speech was heard in the recording. Try again closer to the phone.';\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. The recording is saved; try again when you are back online.';\n if (/no speech|has no speech/i.test(message))\n return 'No speech was heard in the recording. Try again closer to the phone.';\n // Every exec failure starts with the action's name (\"YANTRA_MEETINGS_DICTATION_NOTE failed: ...\"), so\n // only cdecli's own words for a missing connector or action mean Dictate is not set up here.\n if (\n /action '[^']*' not found in connector|not found in registry|is not installed|auto-install (failed|did not complete)/i.test(\n message,\n )\n )\n return 'Dictate is not available on this workspace yet. The recording is saved.';\n // Ours, not theirs: the service behind the note (the connector's neutral \"temporarily unavailable\",\n // or, from an older connector, its raw \"all LLM providers failed\"), or the agent itself failing.\n if (\n /temporarily unavailable|problem on our side|all LLM providers failed|transcription failed|HTTP 5\\d\\d/i.test(\n message,\n )\n )\n return 'Yantra could not write the note right now. This is a problem on our side; the recording is saved, so try again in a few minutes.';\n if (/declined by the content safety rules/i.test(message))\n return 'The note could not be written from this dictation. The recording is saved.';\n if (/timed? ?out|abort/i.test(message)) return 'Writing the note took too long. The recording is saved; try again.';\n return 'The note could not be written. The recording is saved; try again.';\n}\n\nexport async function writeNoteFromRecording(\n audioUri: string,\n deps: DictateDeps,\n opts: { keyterms?: string[]; context?: string; kind?: DictationKind } = {},\n onStage: (stage: DictateStage) => void = () => undefined,\n): Promise<WrittenNote> {\n onStage('uploading');\n const inputUrl = await deps.upload(audioUri);\n onStage('writing');\n const params: Json = {\n input_url: inputUrl,\n ...(opts.keyterms?.length ? { keyterms: opts.keyterms } : {}),\n ...(opts.context?.trim() ? { context: opts.context.trim() } : {}),\n };\n const raw = await execOr(deps, NOTE_ACTION, opts.kind ? { ...params, kind: opts.kind } : params, NOTE_TIMEOUT_MS, {\n action: CLINICAL_NOTE_ACTION,\n params,\n });\n const written = unwrapNote(raw);\n if (!written.transcript && noteIsEmpty(written.note))\n throw new DictateError('empty', 'The dictation has no speech.');\n return written;\n}\n\n/** Whether the hidden transcript fits one call, so the note can be written again from it. */\nexport function canRewrite(redaction: NoteRedaction | undefined): redaction is NoteRedaction {\n if (!redaction?.transcript) return false;\n return (\n fitTranscript({ identifiers: tokensOf(redaction.identifiers), kind: 'general' }, redaction.transcript) ===\n redaction.transcript\n );\n}\n\n/**\n * The note written again as `kind`, from the transcript as the AI first read\n * it: nothing is transcribed and no value leaves the phone. Returns the hidden\n * note and any placeholder the connector added.\n */\nexport async function rewriteNote(\n redaction: NoteRedaction,\n kind: DictationKind,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<{ note: DictationNote; identifiers: NoteIdentifier[]; model?: string }> {\n const raw = await deps.exec(\n DICTATE_CONNECTOR,\n NOTE_ACTION,\n { redacted_transcript: redaction.transcript, identifiers: tokensOf(redaction.identifiers), kind },\n { timeoutMs: NOTE_TIMEOUT_MS },\n );\n const layer = findLayer(raw, (l) => !!asRecord(asRecord(l.redaction)?.note), 'The note came back empty.');\n const rewritten = redactionOf(layer.redaction)!;\n return { note: rewritten.note, identifiers: rewritten.identifiers, model: str(layer.model) || undefined };\n}\n\n/** The AI's suggestions on a note, asked for with its hidden version only. */\nexport async function suggestFromNote(\n redaction: NoteRedaction,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<{ items: NoteSuggestion[]; identifiers: NoteIdentifier[] }> {\n const rest = { note: redaction.note, identifiers: tokensOf(redaction.identifiers) };\n const transcript = fitTranscript(rest, redaction.transcript);\n const raw = await execOr(\n deps,\n SUGGEST_ACTION,\n { ...rest, transcript },\n SUGGEST_TIMEOUT_MS,\n redaction.note.kind === 'clinical'\n ? { action: CLINICAL_SUGGEST_ACTION, params: { ...rest, note: toClinical(redaction.note), transcript } }\n : undefined,\n );\n const layer = findLayer(\n raw,\n (l) => Array.isArray(l.suggestions) || (l.successful === false && !!str(l.error)),\n 'The suggestions came back empty.',\n );\n if (!Array.isArray(layer.suggestions)) throw new DictateError('failed', str(layer.error));\n const items = layer.suggestions\n .map(asRecord)\n .filter((s): s is Json => !!s && SUGGESTION_KINDS.includes(str(s.kind) as SuggestionKind) && !!str(s.text))\n .map((s) => ({ kind: str(s.kind) as SuggestionKind, text: str(s.text), why: str(s.why) }));\n return { items, identifiers: identifiersOf(layer.identifiers) };\n}\n\n/** Why there are no suggestions, in words a person can act on. */\nexport function suggestErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Suggestions are not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not read the note right now. This is a problem on our side; try again in a few minutes.';\n if (/timed? ?out|abort/i.test(message)) return 'Reading the note took too long. Try again.';\n return 'The suggestions could not be written. Try again.';\n}\n\n/** Why the note could not be written again. */\nexport function rewriteErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Rewriting is not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not rewrite the note right now. This is a problem on our side; try again in a few minutes.';\n if (/timed? ?out|abort/i.test(message)) return 'Rewriting the note took too long. Try again.';\n return 'The note could not be rewritten. Try again.';\n}\n\nexport interface Answer {\n /** The message as the AI read it: known names and numbers as placeholders. */\n asked: string;\n answer: string;\n /** Placeholders the connector added (a new number typed in), with what they stand for. */\n identifiers: NoteIdentifier[];\n}\n\n/**\n * A chat message about the note. The AI reads the hidden note and transcript,\n * the earlier turns as it saw them, and the message with every name and number\n * this dictation knows swapped for its placeholder before it leaves the phone.\n */\nexport async function askAboutNote(\n record: DictationRecord,\n message: string,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<Answer> {\n const { redaction } = record;\n if (!redaction) throw new DictateError('unavailable', 'This note was written before names were hidden.');\n const known = knownIdentifiers(record);\n const asked = hideKnown(message.trim(), known).text;\n const turns: Array<Pick<ChatTurn, 'role' | 'text'>> = (record.chat?.turns ?? [])\n .slice(-CHAT_CONTEXT_TURNS)\n .map(({ role, text }) => ({ role, text }));\n const rest = { note: redaction.note, identifiers: tokensOf(known), turns, message: asked };\n const raw = await deps.exec(\n DICTATE_CONNECTOR,\n ASK_ACTION,\n { ...rest, transcript: fitTranscript(rest, redaction.transcript) },\n { timeoutMs: ASK_TIMEOUT_MS },\n );\n const layer = findLayer(raw, (l) => typeof l.answer === 'string', 'The answer came back empty.');\n const answer = str(layer.answer);\n if (!answer) throw new DictateError('failed', 'The answer came back empty.');\n return { asked: str(layer.message) || asked, answer, identifiers: identifiersOf(layer.identifiers) };\n}\n\n/** Why a chat message got no answer. */\nexport function askErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Asking about a note is not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not answer right now. This is a problem on our side; try again in a few minutes.';\n if (/timed?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AACT"}
|
|
1
|
+
{"version":3,"file":"dictateClient.js","sources":["../../../src/features/dictate/dictateClient.ts"],"sourcesContent":["/**\n * Recording -> notes that fit it. The recording is uploaded first and handed\n * to the connector as a URL (connector params travel as one CLI argument,\n * capped at 128 KB - audio never rides inline), then\n * YANTRA_MEETINGS_DICTATION_NOTE transcribes it, works out what it is (a\n * visit, a class, a meeting, an idea, a story...) and writes the note from a\n * transcript whose identifiers are placeholders; it returns the note both ways.\n *\n * Everything after that reads the hidden version only, so nothing identifying\n * goes back to the AI from this phone: the suggestions\n * (YANTRA_MEETINGS_DICTATION_SUGGEST), a rewrite as another kind (the note\n * action again, from the hidden transcript), and the chat about the note\n * (YANTRA_MEETINGS_DICTATION_ASK), whose messages have every name and number\n * the note knows swapped for its placeholder here first.\n *\n * A workspace whose connector predates the dictation actions still gets a\n * visit note and its suggestions from the clinical ones.\n */\nimport type { RemoteConnectorExec } from '../canvas/videoEditor/remoteMediaClient';\nimport { asRecord, noteIsEmpty, shapeNote, str, toClinical } from './noteShape';\nimport { hideKnown, knownIdentifiers } from './privacy';\nimport type {\n ChatTurn,\n DictationKind,\n DictationNote,\n DictationRecord,\n NoteIdentifier,\n NoteRedaction,\n NoteSuggestion,\n SuggestionKind,\n} from './types';\n\nexport const DICTATE_CONNECTOR = 'yantra-meetings';\nexport const NOTE_ACTION = 'YANTRA_MEETINGS_DICTATION_NOTE';\nexport const SUGGEST_ACTION = 'YANTRA_MEETINGS_DICTATION_SUGGEST';\nexport const ASK_ACTION = 'YANTRA_MEETINGS_DICTATION_ASK';\nexport const SPEAK_ACTION = 'YANTRA_MEETINGS_DICTATION_SPEAK';\n/** What a connector from before the dictation actions offers: a visit note and its suggestions. */\nexport const CLINICAL_NOTE_ACTION = 'YANTRA_MEETINGS_CLINICAL_NOTE';\nexport const CLINICAL_SUGGEST_ACTION = 'YANTRA_MEETINGS_CLINICAL_SUGGEST';\n/** A read of one note runs about ten seconds. */\nexport const SUGGEST_TIMEOUT_MS = 4 * 60_000;\nexport const ASK_TIMEOUT_MS = 3 * 60_000;\n/** One spoken piece comes back in a second or two. */\nexport const SPEAK_TIMEOUT_MS = 60_000;\n/** Transcription plus the note runs ~10 s for two minutes of speech; an hour's dictation stays well inside this. */\nexport const NOTE_TIMEOUT_MS = 10 * 60_000;\n/** Connector params ride as one CLI argument capped at 128 KB; what goes back to the AI stays under this. */\nexport const PARAMS_MAX_BYTES = 110_000;\n/** The earlier turns a chat message carries. */\nexport const CHAT_CONTEXT_TURNS = 16;\n\nexport type DictateStage = 'uploading' | 'writing';\n\nexport interface DictateDeps {\n exec: RemoteConnectorExec;\n upload: (localUri: string) => Promise<string>;\n}\n\nexport interface WrittenNote {\n note: DictationNote;\n transcript: string;\n model?: string;\n /** Absent from a connector that does not hide identifiers yet. */\n redaction?: NoteRedaction;\n}\n\nexport class DictateError extends Error {\n constructor(\n readonly kind: 'offline' | 'unavailable' | 'empty' | 'failed',\n message: string,\n ) {\n super(message);\n this.name = 'DictateError';\n }\n}\n\ntype Json = Record<string, unknown>;\nconst SUGGESTION_KINDS: SuggestionKind[] = ['missing', 'safety', 'coding', 'follow_up', 'check', 'question'];\n\n/** cdecli's words for an action this workspace's connector does not have (yet). */\nconst MISSING_ACTION = /action '[^']*' not found in connector/i;\n\n/** `action`, or on a connector that does not have it, `legacy` (when there is one). */\nasync function execOr(\n deps: Pick<DictateDeps, 'exec'>,\n action: string,\n params: Json,\n timeoutMs: number,\n legacy?: { action: string; params: Json },\n): Promise<unknown> {\n try {\n return await deps.exec(DICTATE_CONNECTOR, action, params, { timeoutMs });\n } catch (err) {\n if (!legacy || !MISSING_ACTION.test(err instanceof Error ? err.message : String(err))) throw err;\n return deps.exec(DICTATE_CONNECTOR, legacy.action, legacy.params, { timeoutMs });\n }\n}\n\n/** The first layer (the reply, its `data`, its `result`...) that `has` accepts; the connector's own error if none. */\nfunction findLayer(raw: unknown, has: (layer: Json) => boolean, empty: string): Json {\n let layer = asRecord(raw);\n const seen: Json[] = [];\n for (let depth = 0; layer && depth < 6; depth += 1) {\n if (has(layer)) return layer;\n seen.push(layer);\n layer = asRecord(layer.data) ?? asRecord(layer.result);\n }\n const reason = seen\n .flatMap((l) => [l.error, l.message, l.stderr])\n .find((v): v is string => typeof v === 'string' && v.trim().length > 0);\n throw new DictateError('failed', reason ?? empty);\n}\n\n/** UTF-8 bytes, over-counted for astral characters (which only makes the budget safer). */\nfunction utf8Bytes(text: string): number {\n let n = 0;\n for (let i = 0; i < text.length; i += 1) {\n const c = text.charCodeAt(i);\n if (c < 0x80) n += 1;\n else if (c < 0x800) n += 2;\n else n += 3;\n }\n return n;\n}\n\n/** The transcript cut (at the end) until the params carrying it fit one connector call. */\nexport function fitTranscript(rest: Json, transcript: string): string {\n const budget = PARAMS_MAX_BYTES - utf8Bytes(JSON.stringify(rest)) - 32;\n let fitted = transcript;\n while (fitted && utf8Bytes(JSON.stringify(fitted)) > budget)\n fitted = fitted.slice(0, Math.floor(fitted.length * 0.9));\n return fitted;\n}\n\n/** Only well-formed placeholders: a malformed one could not be put back. */\nexport function identifiersOf(v: unknown): NoteIdentifier[] {\n return (Array.isArray(v) ? v : [])\n .map(asRecord)\n .filter((i): i is Json => !!i && /^\\[[A-Z]+_\\d+\\]$/.test(str(i.token)) && !!str(i.value))\n .map((i) => ({ token: str(i.token), value: str(i.value), kind: str(i.kind) }));\n}\n\n/** Which placeholders exist, so a new one numbers on; never what they stand for. */\nconst tokensOf = (ids: NoteIdentifier[]) => ids.map(({ token, kind }) => ({ token, kind }));\n\nfunction redactionOf(v: unknown): NoteRedaction | undefined {\n const r = asRecord(v);\n const note = asRecord(r?.note);\n if (!r || !note) return undefined;\n return {\n method: r.method === 'patterns' ? 'patterns' : 'entities',\n note: shapeNote(note),\n transcript: str(r.transcript),\n identifiers: identifiersOf(r.identifiers),\n };\n}\n\n/** The note whatever wraps it ({ data: { note } }, { result: ... }), shaped defensively. */\nexport function unwrapNote(raw: unknown): WrittenNote {\n const layer = findLayer(raw, (l) => !!asRecord(l.note), 'The note came back empty.');\n const redaction = redactionOf(layer.redaction);\n return {\n note: shapeNote(asRecord(layer.note)!),\n transcript: str(asRecord(layer.transcript)?.text),\n model: str(layer.model) || undefined,\n ...(redaction ? { redaction } : {}),\n };\n}\n\n/** A message a person can act on, never a stack trace. */\nexport function dictateErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (err instanceof DictateError && err.kind === 'empty')\n return 'No speech was heard in the recording. Try again closer to the phone.';\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. The recording is saved; try again when you are back online.';\n if (/no speech|has no speech/i.test(message))\n return 'No speech was heard in the recording. Try again closer to the phone.';\n // Every exec failure starts with the action's name (\"YANTRA_MEETINGS_DICTATION_NOTE failed: ...\"), so\n // only cdecli's own words for a missing connector or action mean Dictate is not set up here.\n if (\n /action '[^']*' not found in connector|not found in registry|is not installed|auto-install (failed|did not complete)/i.test(\n message,\n )\n )\n return 'Dictate is not available on this workspace yet. The recording is saved.';\n // Ours, not theirs: the service behind the note (the connector's neutral \"temporarily unavailable\",\n // or, from an older connector, its raw \"all LLM providers failed\"), or the agent itself failing.\n if (\n /temporarily unavailable|problem on our side|all LLM providers failed|transcription failed|HTTP 5\\d\\d/i.test(\n message,\n )\n )\n return 'Yantra could not write the note right now. This is a problem on our side; the recording is saved, so try again in a few minutes.';\n if (/declined by the content safety rules/i.test(message))\n return 'The note could not be written from this dictation. The recording is saved.';\n if (/timed? ?out|abort/i.test(message)) return 'Writing the note took too long. The recording is saved; try again.';\n return 'The note could not be written. The recording is saved; try again.';\n}\n\nexport async function writeNoteFromRecording(\n audioUri: string,\n deps: DictateDeps,\n opts: { keyterms?: string[]; context?: string; kind?: DictationKind } = {},\n onStage: (stage: DictateStage) => void = () => undefined,\n): Promise<WrittenNote> {\n onStage('uploading');\n const inputUrl = await deps.upload(audioUri);\n onStage('writing');\n const params: Json = {\n input_url: inputUrl,\n ...(opts.keyterms?.length ? { keyterms: opts.keyterms } : {}),\n ...(opts.context?.trim() ? { context: opts.context.trim() } : {}),\n };\n const raw = await execOr(deps, NOTE_ACTION, opts.kind ? { ...params, kind: opts.kind } : params, NOTE_TIMEOUT_MS, {\n action: CLINICAL_NOTE_ACTION,\n params,\n });\n const written = unwrapNote(raw);\n if (!written.transcript && noteIsEmpty(written.note))\n throw new DictateError('empty', 'The dictation has no speech.');\n return written;\n}\n\n/** Whether the hidden transcript fits one call, so the note can be written again from it. */\nexport function canRewrite(redaction: NoteRedaction | undefined): redaction is NoteRedaction {\n if (!redaction?.transcript) return false;\n return (\n fitTranscript({ identifiers: tokensOf(redaction.identifiers), kind: 'general' }, redaction.transcript) ===\n redaction.transcript\n );\n}\n\n/**\n * The note written again as `kind`, from the transcript as the AI first read\n * it: nothing is transcribed and no value leaves the phone. Returns the hidden\n * note and any placeholder the connector added.\n */\nexport async function rewriteNote(\n redaction: NoteRedaction,\n kind: DictationKind,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<{ note: DictationNote; identifiers: NoteIdentifier[]; model?: string }> {\n const raw = await deps.exec(\n DICTATE_CONNECTOR,\n NOTE_ACTION,\n { redacted_transcript: redaction.transcript, identifiers: tokensOf(redaction.identifiers), kind },\n { timeoutMs: NOTE_TIMEOUT_MS },\n );\n const layer = findLayer(raw, (l) => !!asRecord(asRecord(l.redaction)?.note), 'The note came back empty.');\n const rewritten = redactionOf(layer.redaction)!;\n return { note: rewritten.note, identifiers: rewritten.identifiers, model: str(layer.model) || undefined };\n}\n\n/** The AI's suggestions on a note, asked for with its hidden version only. */\nexport async function suggestFromNote(\n redaction: NoteRedaction,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<{ items: NoteSuggestion[]; identifiers: NoteIdentifier[] }> {\n const rest = { note: redaction.note, identifiers: tokensOf(redaction.identifiers) };\n const transcript = fitTranscript(rest, redaction.transcript);\n const raw = await execOr(\n deps,\n SUGGEST_ACTION,\n { ...rest, transcript },\n SUGGEST_TIMEOUT_MS,\n redaction.note.kind === 'clinical'\n ? { action: CLINICAL_SUGGEST_ACTION, params: { ...rest, note: toClinical(redaction.note), transcript } }\n : undefined,\n );\n const layer = findLayer(\n raw,\n (l) => Array.isArray(l.suggestions) || (l.successful === false && !!str(l.error)),\n 'The suggestions came back empty.',\n );\n if (!Array.isArray(layer.suggestions)) throw new DictateError('failed', str(layer.error));\n const items = layer.suggestions\n .map(asRecord)\n .filter((s): s is Json => !!s && SUGGESTION_KINDS.includes(str(s.kind) as SuggestionKind) && !!str(s.text))\n .map((s) => ({ kind: str(s.kind) as SuggestionKind, text: str(s.text), why: str(s.why) }));\n return { items, identifiers: identifiersOf(layer.identifiers) };\n}\n\n/** Why there are no suggestions, in words a person can act on. */\nexport function suggestErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Suggestions are not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not read the note right now. This is a problem on our side; try again in a few minutes.';\n if (/timed? ?out|abort/i.test(message)) return 'Reading the note took too long. Try again.';\n return 'The suggestions could not be written. Try again.';\n}\n\n/** Why the note could not be written again. */\nexport function rewriteErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Rewriting is not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not rewrite the note right now. This is a problem on our side; try again in a few minutes.';\n if (/timed? ?out|abort/i.test(message)) return 'Rewriting the note took too long. Try again.';\n return 'The note could not be rewritten. Try again.';\n}\n\nexport interface Answer {\n /** The message as the AI read it: known names and numbers as placeholders. */\n asked: string;\n answer: string;\n /** Placeholders the connector added (a new number typed in), with what they stand for. */\n identifiers: NoteIdentifier[];\n}\n\n/**\n * A chat message about the note. The AI reads the hidden note and transcript,\n * the earlier turns as it saw them, and the message with every name and number\n * this dictation knows swapped for its placeholder before it leaves the phone.\n */\nexport async function askAboutNote(\n record: DictationRecord,\n message: string,\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<Answer> {\n const { redaction } = record;\n if (!redaction) throw new DictateError('unavailable', 'This note was written before names were hidden.');\n const known = knownIdentifiers(record);\n const asked = hideKnown(message.trim(), known).text;\n const turns: Array<Pick<ChatTurn, 'role' | 'text'>> = (record.chat?.turns ?? [])\n .slice(-CHAT_CONTEXT_TURNS)\n .map(({ role, text }) => ({ role, text }));\n const rest = { note: redaction.note, identifiers: tokensOf(known), turns, message: asked };\n const raw = await deps.exec(\n DICTATE_CONNECTOR,\n ASK_ACTION,\n { ...rest, transcript: fitTranscript(rest, redaction.transcript) },\n { timeoutMs: ASK_TIMEOUT_MS },\n );\n const layer = findLayer(raw, (l) => typeof l.answer === 'string', 'The answer came back empty.');\n const answer = str(layer.answer);\n if (!answer) throw new DictateError('failed', 'The answer came back empty.');\n return { asked: str(layer.message) || asked, answer, identifiers: identifiersOf(layer.identifiers) };\n}\n\n/** Why a chat message got no answer. */\nexport function askErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Asking about a note is not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|all LLM providers failed|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not answer right now. This is a problem on our side; try again in a few minutes.';\n if (/timed? ?out|abort/i.test(message)) return 'The answer took too long. Try again.';\n return 'No answer came back. Try again.';\n}\n\n/**\n * One piece of text spoken by the connector's voice, for a phone without its\n * own: the hidden version only, placeholders as labels. Resolves to the MP3,\n * base64; nothing is stored anywhere.\n */\nexport async function speakText(\n text: string,\n identifiers: NoteIdentifier[],\n deps: Pick<DictateDeps, 'exec'>,\n): Promise<string> {\n const raw = await deps.exec(\n DICTATE_CONNECTOR,\n SPEAK_ACTION,\n { text, identifiers: tokensOf(identifiers) },\n { timeoutMs: SPEAK_TIMEOUT_MS },\n );\n const layer = findLayer(raw, (l) => typeof l.audio_base64 === 'string', 'No speech came back.');\n const audio = str(layer.audio_base64);\n if (!audio) throw new DictateError('failed', 'No speech came back.');\n return audio;\n}\n\n/** Why the note or an answer could not be read aloud. */\nexport function readErrorText(err: unknown): string {\n const message = err instanceof Error ? err.message : String(err);\n if (/network request failed|offline|not signed in/i.test(message))\n return 'You are offline or signed out, so it cannot be read aloud. Try again when you are back online.';\n if (/action '[^']*' not found in connector|not found in registry|is not installed/i.test(message))\n return 'Reading aloud is not available on this workspace yet.';\n if (/temporarily unavailable|problem on our side|HTTP 5\\d\\d/i.test(message))\n return 'Yantra could not read it aloud right now. This is a problem on our side; try again in a few minutes.';\n return 'It could not be read aloud. Try again.';\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AAsBO,MAAM,iBAAoB,GAAA;AAC1B,MAAM,WAAc,GAAA;AACpB,MAAM,cAAiB,GAAA;AACvB,MAAM,UAAa,GAAA;AACnB,MAAM,YAAe,GAAA;AAErB,MAAM,oBAAuB,GAAA;AAC7B,MAAM,uBAA0B,GAAA;AAEhC,MAAM,qBAAqB,CAAI,GAAA;AAC/B,MAAM,iBAAiB,CAAI,GAAA;AAE3B,MAAM,gBAAmB,GAAA;AAEzB,MAAM,kBAAkB,EAAK,GAAA;AAE7B,MAAM,gBAAmB,GAAA;AAezB,MAAM,qBAAqB,KAAM,CAAA;AAAA,EACtC,WAAA,CAAqB,MAAsD,OAAiB,EAAA;AAC1F,IAAA,KAAA,CAAM,OAAO,CAAA;AADM,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAEnB,IAAA,IAAA,CAAK,IAAO,GAAA,cAAA;AAAA;AAEhB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,EAAA,MAAM,UAAU,GAAe,YAAA,KAAA,GAAQ,GAAI,CAAA,OAAA,GAAU,OAAO,GAAG,CAAA;AAC/D,EAAA,IAAI,+CAAgD,CAAA,IAAA,CAAK,OAAO,CAAA,EAAU,OAAA,gGAAA;AAC1E,EAAA,IAAI,+EAAgF,CAAA,IAAA,CAAK,OAAO,CAAA,EAAU,OAAA,uDAAA;AAC1G,EAAA,IAAI,yDAA0D,CAAA,IAAA,CAAK,OAAO,CAAA,EAAU,OAAA,sGAAA;AACpF,EAAO,OAAA,wCAAA;AACT"}
|
|
@@ -16,4 +16,28 @@ async function readShowIdentifiers() {
|
|
|
16
16
|
}
|
|
17
17
|
function writeShowIdentifiers(show) {
|
|
18
18
|
AsyncStorage == null ? void 0 : AsyncStorage.setItem(KEY, show ? "1" : "0").catch(() => void 0);
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
|
+
const MIC_KEY = "yantra.dictate.mic.v1";
|
|
21
|
+
async function readMicPreference() {
|
|
22
|
+
if (!AsyncStorage) return "headset";
|
|
23
|
+
try {
|
|
24
|
+
return await AsyncStorage.getItem(MIC_KEY) === "phone" ? "phone" : "headset";
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return "headset";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function writeMicPreference(kind) {
|
|
30
|
+
AsyncStorage == null ? void 0 : AsyncStorage.setItem(MIC_KEY, kind).catch(() => void 0);
|
|
31
|
+
}
|
|
32
|
+
const READ_KEY = "yantra.dictate.readAnswers.v1";
|
|
33
|
+
async function readReadAnswers() {
|
|
34
|
+
if (!AsyncStorage) return true;
|
|
35
|
+
try {
|
|
36
|
+
return await AsyncStorage.getItem(READ_KEY) !== "0";
|
|
37
|
+
} catch (e) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function writeReadAnswers(on) {
|
|
42
|
+
AsyncStorage == null ? void 0 : AsyncStorage.setItem(READ_KEY, on ? "1" : "0").catch(() => void 0);
|
|
43
|
+
}export{readMicPreference,readReadAnswers,readShowIdentifiers,writeMicPreference,writeReadAnswers,writeShowIdentifiers};//# sourceMappingURL=dictatePreference.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictatePreference.js","sources":["../../../src/features/dictate/dictatePreference.ts"],"sourcesContent":["/**\n *
|
|
1
|
+
{"version":3,"file":"dictatePreference.js","sources":["../../../src/features/dictate/dictatePreference.ts"],"sourcesContent":["/**\n * Dictate's choices on this phone: whether a note shows its names and numbers\n * put back or hidden (hidden unless the person chose otherwise; either way the\n * AI only ever saw placeholders), which microphone a dictation starts with, and\n * whether chat answers are read aloud on their own.\n */\nimport type { MicKind } from './micInput';\n\ntype StorageLike = {\n getItem(key: string): Promise<string | null>;\n setItem(key: string, value: string): Promise<void>;\n};\n\nlet AsyncStorage: StorageLike | null = null;\ntry {\n // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require\n AsyncStorage = require('@react-native-async-storage/async-storage').default ?? null;\n} catch {\n AsyncStorage = null;\n}\n\nconst KEY = 'yantra.dictate.showIdentifiers.v1';\n\nexport async function readShowIdentifiers(): Promise<boolean> {\n if (!AsyncStorage) return false;\n try {\n return (await AsyncStorage.getItem(KEY)) === '1';\n } catch {\n return false;\n }\n}\n\nexport function writeShowIdentifiers(show: boolean): void {\n AsyncStorage?.setItem(KEY, show ? '1' : '0').catch(() => undefined);\n}\n\nconst MIC_KEY = 'yantra.dictate.mic.v1';\n\n/** The microphone a dictation starts with: a connected headset (AirPods) unless the person chose the phone's. */\nexport async function readMicPreference(): Promise<MicKind> {\n if (!AsyncStorage) return 'headset';\n try {\n return (await AsyncStorage.getItem(MIC_KEY)) === 'phone' ? 'phone' : 'headset';\n } catch {\n return 'headset';\n }\n}\n\nexport function writeMicPreference(kind: MicKind): void {\n AsyncStorage?.setItem(MIC_KEY, kind).catch(() => undefined);\n}\n\nconst READ_KEY = 'yantra.dictate.readAnswers.v1';\n\n/**\n * Whether answers in a note's chat are read aloud on their own: on unless the\n * person turned it off. Even on, one is only read when it was asked by voice or\n * the sound goes to the ear (AirPods), never out of the phone's speaker unasked.\n */\nexport async function readReadAnswers(): Promise<boolean> {\n if (!AsyncStorage) return true;\n try {\n return (await AsyncStorage.getItem(READ_KEY)) !== '0';\n } catch {\n return true;\n }\n}\n\nexport function writeReadAnswers(on: boolean): void {\n AsyncStorage?.setItem(READ_KEY, on ? '1' : '0').catch(() => undefined);\n}\n"],"names":[],"mappings":"AAAA,IAAA,EAAA;AAWA,IAAI,YAAmC,GAAA,IAAA;AACvC,IAAI;AAEF,EAAA,YAAA,GAAA,CAAe,EAAQ,GAAA,OAAA,CAAA,2CAA2C,CAAE,CAAA,OAAA,KAArD,IAAgE,GAAA,EAAA,GAAA,IAAA;AACjF,CAAQ,CAAA,OAAA,CAAA,EAAA;AACN,EAAe,YAAA,GAAA,IAAA;AACjB;AACA,MAAM,GAAM,GAAA,mCAAA;AACZ,eAAsB,mBAAwC,GAAA;AAC5D,EAAI,IAAA,CAAC,cAAqB,OAAA,KAAA;AAC1B,EAAI,IAAA;AACF,IAAA,OAAQ,MAAM,YAAA,CAAa,OAAQ,CAAA,GAAG,CAAO,KAAA,GAAA;AAAA,GACvC,CAAA,OAAA,CAAA,EAAA;AACN,IAAO,OAAA,KAAA;AAAA;AAEX;AACO,SAAS,qBAAqB,IAAqB,EAAA;AACxD,EAAA,YAAA,IAAA,IAAA,GAAA,MAAA,GAAA,YAAA,CAAc,QAAQ,GAAK,EAAA,IAAA,GAAO,GAAM,GAAA,GAAA,CAAA,CAAK,MAAM,MAAM,MAAA,CAAA;AAC3D;AACA,MAAM,OAAU,GAAA,uBAAA;AAGhB,eAAsB,iBAAsC,GAAA;AAC1D,EAAI,IAAA,CAAC,cAAqB,OAAA,SAAA;AAC1B,EAAI,IAAA;AACF,IAAA,OAAQ,MAAM,YAAa,CAAA,OAAA,CAAQ,OAAO,CAAA,KAAO,UAAU,OAAU,GAAA,SAAA;AAAA,GAC/D,CAAA,OAAA,CAAA,EAAA;AACN,IAAO,OAAA,SAAA;AAAA;AAEX;AACO,SAAS,mBAAmB,IAAqB,EAAA;AACtD,EAAA,YAAA,IAAA,IAAA,GAAA,MAAA,GAAA,YAAA,CAAc,OAAQ,CAAA,OAAA,EAAS,IAAM,CAAA,CAAA,KAAA,CAAM,MAAM,MAAA,CAAA;AACnD;AACA,MAAM,QAAW,GAAA,+BAAA;AAOjB,eAAsB,eAAoC,GAAA;AACxD,EAAI,IAAA,CAAC,cAAqB,OAAA,IAAA;AAC1B,EAAI,IAAA;AACF,IAAA,OAAQ,MAAM,YAAA,CAAa,OAAQ,CAAA,QAAQ,CAAO,KAAA,GAAA;AAAA,GAC5C,CAAA,OAAA,CAAA,EAAA;AACN,IAAO,OAAA,IAAA;AAAA;AAEX;AACO,SAAS,iBAAiB,EAAmB,EAAA;AAClD,EAAA,YAAA,IAAA,IAAA,GAAA,MAAA,GAAA,YAAA,CAAc,QAAQ,QAAU,EAAA,EAAA,GAAK,GAAM,GAAA,GAAA,CAAA,CAAK,MAAM,MAAM,MAAA,CAAA;AAC9D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {requireOptionalNativeModule}from'expo-modules-core';function optional(name) {
|
|
2
|
+
try {
|
|
3
|
+
return requireOptionalNativeModule(name);
|
|
4
|
+
} catch (e) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
let voice;
|
|
9
|
+
let ears;
|
|
10
|
+
function dictateVoiceNative() {
|
|
11
|
+
if (voice === void 0) voice = optional("YantraDictateVoice");
|
|
12
|
+
return voice;
|
|
13
|
+
}
|
|
14
|
+
function speechRecognitionNative() {
|
|
15
|
+
if (ears === void 0) {
|
|
16
|
+
const mod = optional("ExpoSpeechRecognition");
|
|
17
|
+
let usable = !!mod;
|
|
18
|
+
try {
|
|
19
|
+
if (mod && typeof mod.isRecognitionAvailable === "function") usable = mod.isRecognitionAvailable();
|
|
20
|
+
} catch (e) {
|
|
21
|
+
usable = false;
|
|
22
|
+
}
|
|
23
|
+
ears = usable ? mod : null;
|
|
24
|
+
}
|
|
25
|
+
return ears;
|
|
26
|
+
}
|
|
27
|
+
function headphonesConnected() {
|
|
28
|
+
var _a;
|
|
29
|
+
try {
|
|
30
|
+
return ((_a = dictateVoiceNative()) == null ? void 0 : _a.headphonesConnected()) === true;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}export{dictateVoiceNative,headphonesConnected,speechRecognitionNative};//# sourceMappingURL=dictateVoice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictateVoice.js","sources":["../../../src/features/dictate/dictateVoice.ts"],"sourcesContent":["/**\n * The phone's own voice and ears for Dictate, as this binary has them:\n * - YantraDictateVoice (portable-devices/mobile/modules/yantra-background-recording):\n * speaks on the device, so nothing leaves the phone, and says whether sound\n * goes to the ear (AirPods, headphones).\n * - ExpoSpeechRecognition: hears a spoken question, on the device when it can.\n *\n * Optional on purpose: an over-the-air update reaches binaries built before\n * either module. No voice falls back to the connector's (names hidden); no\n * speech recognition means no microphone button in the note's chat.\n */\nimport { requireOptionalNativeModule } from 'expo-modules-core';\n\nexport type SpeechEnd = { id: string; state: 'done' | 'stopped' | 'error' };\n\nexport interface DictateVoiceNative {\n speak(id: string, text: string, language?: string | null): Promise<void>;\n stop(): Promise<void>;\n headphonesConnected(): boolean;\n addListener(event: 'onSpeech', listener: (event: SpeechEnd) => void): { remove(): void };\n}\n\nexport interface SpeechRecognitionNative {\n isRecognitionAvailable?: () => boolean;\n supportsOnDeviceRecognition?: () => boolean;\n requestPermissionsAsync(): Promise<{ granted: boolean }>;\n start(options: Record<string, unknown>): void;\n stop(): void;\n abort(): void;\n addListener(\n event: 'result' | 'end' | 'error',\n listener: (event: {\n results?: Array<{ transcript?: string }>;\n isFinal?: boolean;\n error?: string;\n message?: string;\n }) => void,\n ): { remove(): void };\n}\n\nfunction optional<T>(name: string): T | null {\n try {\n return requireOptionalNativeModule<T>(name);\n } catch {\n return null;\n }\n}\n\nlet voice: DictateVoiceNative | null | undefined;\nlet ears: SpeechRecognitionNative | null | undefined;\n\nexport function dictateVoiceNative(): DictateVoiceNative | null {\n if (voice === undefined) voice = optional<DictateVoiceNative>('YantraDictateVoice');\n return voice;\n}\n\nexport function speechRecognitionNative(): SpeechRecognitionNative | null {\n if (ears === undefined) {\n const mod = optional<SpeechRecognitionNative>('ExpoSpeechRecognition');\n let usable = !!mod;\n try {\n if (mod && typeof mod.isRecognitionAvailable === 'function') usable = mod.isRecognitionAvailable();\n } catch {\n usable = false;\n }\n ears = usable ? mod : null;\n }\n return ears;\n}\n\n/** Sound goes to the ear right now. Unknown (an older binary) reads as no. */\nexport function headphonesConnected(): boolean {\n try {\n return dictateVoiceNative()?.headphonesConnected() === true;\n } catch {\n return false;\n }\n}\n"],"names":[],"mappings":"4DA4CA,SAAS,SAAY,IAAwB,EAAA;AAC3C,EAAI,IAAA;AACF,IAAA,OAAO,4BAA+B,IAAI,CAAA;AAAA,GACpC,CAAA,OAAA,CAAA,EAAA;AACN,IAAO,OAAA,IAAA;AAAA;AAEX;AACA,IAAI,KAAA;AACJ,IAAI,IAAA;AACG,SAAS,kBAAgD,GAAA;AAC9D,EAAA,IAAI,KAAU,KAAA,MAAA,EAAmB,KAAA,GAAA,QAAA,CAA6B,oBAAoB,CAAA;AAClF,EAAO,OAAA,KAAA;AACT;AACO,SAAS,uBAA0D,GAAA;AACxE,EAAA,IAAI,SAAS,MAAW,EAAA;AACtB,IAAM,MAAA,GAAA,GAAM,SAAkC,uBAAuB,CAAA;AACrE,IAAI,IAAA,MAAA,GAAS,CAAC,CAAC,GAAA;AACf,IAAI,IAAA;AACF,MAAA,IAAI,OAAO,OAAO,GAAA,CAAI,2BAA2B,UAAY,EAAA,MAAA,GAAS,IAAI,sBAAuB,EAAA;AAAA,KAC3F,CAAA,OAAA,CAAA,EAAA;AACN,MAAS,MAAA,GAAA,KAAA;AAAA;AAEX,IAAA,IAAA,GAAO,SAAS,GAAM,GAAA,IAAA;AAAA;AAExB,EAAO,OAAA,IAAA;AACT;AAGO,SAAS,mBAA+B,GAAA;AAxE/C,EAAA,IAAA,EAAA;AAyEE,EAAI,IAAA;AACF,IAAO,OAAA,CAAA,CAAA,EAAA,GAAA,kBAAA,EAAA,KAAA,IAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAsB,mBAA0B,EAAA,MAAA,IAAA;AAAA,GACjD,CAAA,OAAA,CAAA,EAAA;AACN,IAAO,OAAA,KAAA;AAAA;AAEX"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const BUILT_IN = /^MicrophoneBuiltIn$/i;
|
|
2
|
+
const BLUETOOTH = /bluetooth/i;
|
|
3
|
+
const WIRED = /wired|headset/i;
|
|
4
|
+
const AIRPODS = /AirPods(?:\s+(?:Pro|Max))?(?:\s+\d)?/i;
|
|
5
|
+
function withoutOwner(name) {
|
|
6
|
+
return name.replace(/^.*?['’]s\s+/, "").trim();
|
|
7
|
+
}
|
|
8
|
+
function micLabel(input, phone) {
|
|
9
|
+
var _a;
|
|
10
|
+
if (BUILT_IN.test(input.type)) return `${phone} microphone`;
|
|
11
|
+
const airpods = (_a = AIRPODS.exec(input.name)) == null ? void 0 : _a[0];
|
|
12
|
+
if (airpods) return airpods;
|
|
13
|
+
const own = withoutOwner(input.name);
|
|
14
|
+
if (own) return own;
|
|
15
|
+
if (BLUETOOTH.test(input.type)) return "Bluetooth headset";
|
|
16
|
+
if (WIRED.test(input.type)) return "Wired headset";
|
|
17
|
+
return "External microphone";
|
|
18
|
+
}
|
|
19
|
+
function micOf(input, phone) {
|
|
20
|
+
return {
|
|
21
|
+
uid: input.uid,
|
|
22
|
+
kind: BUILT_IN.test(input.type) ? "phone" : "headset",
|
|
23
|
+
label: micLabel(input, phone)
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function micsOf(inputs, phone) {
|
|
27
|
+
const seen = /* @__PURE__ */ new Set();
|
|
28
|
+
return (inputs != null ? inputs : []).filter((input) => !!(input == null ? void 0 : input.uid) && !seen.has(input.uid) && !!seen.add(input.uid)).map((input) => micOf(input, phone));
|
|
29
|
+
}
|
|
30
|
+
function chooseMic(mics, prefer) {
|
|
31
|
+
var _a, _b, _c;
|
|
32
|
+
return (_c = (_b = (_a = mics.find((m) => m.kind === prefer)) != null ? _a : mics.find((m) => m.kind === "phone")) != null ? _b : mics[0]) != null ? _c : null;
|
|
33
|
+
}
|
|
34
|
+
function otherMic(mics, current) {
|
|
35
|
+
var _a;
|
|
36
|
+
if (!current) return null;
|
|
37
|
+
return (_a = mics.find((m) => m.kind !== current.kind)) != null ? _a : null;
|
|
38
|
+
}export{chooseMic,micLabel,micOf,micsOf,otherMic};//# sourceMappingURL=micInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"micInput.js","sources":["../../../src/features/dictate/micInput.ts"],"sourcesContent":["/**\n * Which microphone a dictation records from. With AirPods (or any headset)\n * connected, Dictate records through them by default: they hear the person\n * wearing them, close up, wherever the phone is. A class or a meeting is heard\n * better by the phone, so the recording screen offers the switch and the\n * choice is remembered.\n *\n * expo-audio lists the inputs once the recorder is prepared: iOS port types\n * (BluetoothHFP, MicrophoneWired, MicrophoneBuiltIn, CarAudio...) and Android\n * device types (BluetoothSCO, MicrophoneWired, MicrophoneBuiltIn). Choosing a\n * Bluetooth one on Android turns its headset microphone on (SCO); choosing the\n * phone's turns it off again.\n *\n * Pure: no native imports, so it runs under jest.\n */\nimport type { RecordingInput } from 'expo-audio';\n\nexport type MicKind = 'headset' | 'phone';\n\nexport interface Mic {\n uid: string;\n kind: MicKind;\n /** How it reads on screen: \"AirPods Pro\", \"iPhone microphone\". Never the owner's name. */\n label: string;\n}\n\nconst BUILT_IN = /^MicrophoneBuiltIn$/i;\nconst BLUETOOTH = /bluetooth/i;\nconst WIRED = /wired|headset/i;\n/** \"AirPods\", \"AirPods Pro\", \"AirPods Max\", \"AirPods Pro 2\". */\nconst AIRPODS = /AirPods(?:\\s+(?:Pro|Max))?(?:\\s+\\d)?/i;\n\n/** A device's own name without its owner (\"Alex's Galaxy Buds\" -> \"Galaxy Buds\"). */\nfunction withoutOwner(name: string): string {\n return name.replace(/^.*?['’]s\\s+/, '').trim();\n}\n\n/**\n * How an input reads on screen. `phone` names the built-in microphone's\n * device (\"iPhone\", \"iPad\", \"Phone\").\n */\nexport function micLabel(input: Pick<RecordingInput, 'name' | 'type'>, phone: string): string {\n if (BUILT_IN.test(input.type)) return `${phone} microphone`;\n const airpods = AIRPODS.exec(input.name)?.[0];\n if (airpods) return airpods;\n const own = withoutOwner(input.name);\n if (own) return own;\n if (BLUETOOTH.test(input.type)) return 'Bluetooth headset';\n if (WIRED.test(input.type)) return 'Wired headset';\n return 'External microphone';\n}\n\n/** Anything that is not the phone's own microphone counts as a headset: AirPods, earbuds, a wired or car mic. */\nexport function micOf(input: RecordingInput, phone: string): Mic {\n return { uid: input.uid, kind: BUILT_IN.test(input.type) ? 'phone' : 'headset', label: micLabel(input, phone) };\n}\n\n/** The inputs a recorder offers, once each. */\nexport function micsOf(inputs: RecordingInput[] | null | undefined, phone: string): Mic[] {\n const seen = new Set<string>();\n return (inputs ?? [])\n .filter((input) => !!input?.uid && !seen.has(input.uid) && !!seen.add(input.uid))\n .map((input) => micOf(input, phone));\n}\n\n/** The microphone to record from: the preferred kind when it is there, else the phone's, else whatever there is. */\nexport function chooseMic(mics: Mic[], prefer: MicKind): Mic | null {\n return mics.find((m) => m.kind === prefer) ?? mics.find((m) => m.kind === 'phone') ?? mics[0] ?? null;\n}\n\n/** The other kind of microphone to offer, when there is one. */\nexport function otherMic(mics: Mic[], current: Mic | null): Mic | null {\n if (!current) return null;\n return mics.find((m) => m.kind !== current.kind) ?? null;\n}\n"],"names":[],"mappings":"AAuBA,MAAM,QAAW,GAAA,sBAAA;AACjB,MAAM,SAAY,GAAA,YAAA;AAClB,MAAM,KAAQ,GAAA,gBAA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S,KAAA,KAAA,CAAC,EAAC,KAAA,IAAA,IAAA,GAAA,MAAA,GAAA,KAAA,CAAO,GAAO,CAAA,IAAA,CAAC,IAAK,CAAA,GAAA,CAAI,KAAM,CAAA,GAAG,CAAK,IAAA,CAAC,CAAC,IAAA,CAAK,GAAI,CAAA,KAAA,CAAM,GAAG,CAAC,CAAE,CAAA,GAAA,CAAI,CAAS,KAAA,KAAA,KAAA,CAAM,KAAO,EAAA,KAAK,CAAC,CAAA;AACvI;AAGgB,SAAA,SAAA,CAAU,MAAa,MAA6B,EAAA;AAjEpE,EAAA,IAAA,EAAA,EAAA,EAAA,EAAA,EAAA;AAkEE,EAAA,OAAA,CAAO,sBAAK,IAAK,CAAA,CAAA,CAAA,KAAK,EAAE,IAAS,KAAA,MAAM,MAAhC,IAAqC,GAAA,EAAA,GAAA,IAAA,CAAK,KAAK,CAAK,CAAA,KAAA,CAAA,CAAE,SAAS,OAAO,CAAA,KAAtE,YAA2E,IAAK,CAAA,CAAC,MAAjF,IAAsF,GAAA,EAAA,GAAA,IAAA;AAC/F;AAGgB,SAAA,QAAA,CAAS,MAAa,OAAiC,EAAA;AAtEvE,EAAA,IAAA,EAAA;AAuEE,EAAI,IAAA,CAAC,SAAgB,OAAA,IAAA;AACrB,EAAO,OAAA,CAAA,EAAA,GAAA,IAAA,CAAK,KAAK,CAAK,CAAA,KAAA,CAAA,CAAE,SAAS,OAAQ,CAAA,IAAI,MAAtC,IAA2C,GAAA,EAAA,GAAA,IAAA;AACpD"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {useMemo,useEffect,useState,useRef,useCallback}from'react';import {setAudioModeAsync,createAudioPlayer}from'expo-audio';import {readErrorText,speakText}from'./dictateClient.js';import {dictateVoiceNative}from'./dictateVoice.js';import {splitForSpeech}from'./speechText.js';let nextId = 0;
|
|
2
|
+
function deviceVoice(native) {
|
|
3
|
+
const waiting = /* @__PURE__ */ new Map();
|
|
4
|
+
const sub = native.addListener("onSpeech", (event) => {
|
|
5
|
+
var _a;
|
|
6
|
+
(_a = waiting.get(event.id)) == null ? void 0 : _a(event.state);
|
|
7
|
+
waiting.delete(event.id);
|
|
8
|
+
});
|
|
9
|
+
return {
|
|
10
|
+
kind: "device",
|
|
11
|
+
load: async (text) => ({
|
|
12
|
+
play: () => new Promise((resolve, reject) => {
|
|
13
|
+
nextId += 1;
|
|
14
|
+
const id = `dictate-${nextId}`;
|
|
15
|
+
waiting.set(id, (state) => state === "error" ? reject(new Error("the phone could not speak it")) : resolve());
|
|
16
|
+
native.speak(id, text, null).catch((err) => {
|
|
17
|
+
waiting.delete(id);
|
|
18
|
+
reject(err);
|
|
19
|
+
});
|
|
20
|
+
}),
|
|
21
|
+
stop: () => {
|
|
22
|
+
void native.stop().catch(() => void 0);
|
|
23
|
+
},
|
|
24
|
+
dispose: () => void 0
|
|
25
|
+
}),
|
|
26
|
+
dispose: () => sub.remove()
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function loadFs() {
|
|
30
|
+
return require("expo-file-system");
|
|
31
|
+
}
|
|
32
|
+
function cloudVoice(deps, files) {
|
|
33
|
+
return {
|
|
34
|
+
kind: "cloud",
|
|
35
|
+
load: async (text, identifiers) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const fs = loadFs();
|
|
38
|
+
const audio = await speakText(text, identifiers, deps);
|
|
39
|
+
nextId += 1;
|
|
40
|
+
const uri = `${(_a = fs.cacheDirectory) != null ? _a : ""}dictate-voice-${nextId}.mp3`;
|
|
41
|
+
await fs.writeAsStringAsync(uri, audio, {
|
|
42
|
+
encoding: "base64"
|
|
43
|
+
});
|
|
44
|
+
let player = null;
|
|
45
|
+
let ended = null;
|
|
46
|
+
return {
|
|
47
|
+
play: () => new Promise((resolve) => {
|
|
48
|
+
ended = resolve;
|
|
49
|
+
player = createAudioPlayer({
|
|
50
|
+
uri
|
|
51
|
+
});
|
|
52
|
+
player.addListener("playbackStatusUpdate", (status) => {
|
|
53
|
+
if (status.didJustFinish) resolve();
|
|
54
|
+
});
|
|
55
|
+
player.play();
|
|
56
|
+
}),
|
|
57
|
+
stop: () => {
|
|
58
|
+
player == null ? void 0 : player.pause();
|
|
59
|
+
ended == null ? void 0 : ended();
|
|
60
|
+
},
|
|
61
|
+
dispose: () => {
|
|
62
|
+
player == null ? void 0 : player.remove();
|
|
63
|
+
player = null;
|
|
64
|
+
void fs.deleteAsync(uri, {
|
|
65
|
+
idempotent: true
|
|
66
|
+
}).catch(() => void 0);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
dispose: () => void 0
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function useReadAloud(deps, makeVoice) {
|
|
74
|
+
const voice = useMemo(() => {
|
|
75
|
+
if (makeVoice) return makeVoice();
|
|
76
|
+
const native = dictateVoiceNative();
|
|
77
|
+
return native ? deviceVoice(native) : cloudVoice(deps);
|
|
78
|
+
}, [deps, makeVoice]);
|
|
79
|
+
useEffect(() => () => voice.dispose(), [voice]);
|
|
80
|
+
const [readingId, setReadingId] = useState(null);
|
|
81
|
+
const [error, setError] = useState(null);
|
|
82
|
+
const runRef = useRef(0);
|
|
83
|
+
const currentRef = useRef(null);
|
|
84
|
+
const stop = useCallback(() => {
|
|
85
|
+
var _a;
|
|
86
|
+
runRef.current += 1;
|
|
87
|
+
(_a = currentRef.current) == null ? void 0 : _a.stop();
|
|
88
|
+
currentRef.current = null;
|
|
89
|
+
setReadingId(null);
|
|
90
|
+
}, []);
|
|
91
|
+
const read = useCallback((id, textFor, identifiers = []) => {
|
|
92
|
+
stop();
|
|
93
|
+
runRef.current += 1;
|
|
94
|
+
const run = runRef.current;
|
|
95
|
+
const live = () => runRef.current === run;
|
|
96
|
+
setReadingId(id);
|
|
97
|
+
setError(null);
|
|
98
|
+
void (async () => {
|
|
99
|
+
let next = null;
|
|
100
|
+
try {
|
|
101
|
+
await setAudioModeAsync({
|
|
102
|
+
allowsRecording: false,
|
|
103
|
+
playsInSilentMode: true,
|
|
104
|
+
shouldPlayInBackground: false
|
|
105
|
+
}).catch(() => void 0);
|
|
106
|
+
const pieces = splitForSpeech(textFor(voice.kind));
|
|
107
|
+
next = pieces.length ? voice.load(pieces[0], identifiers) : null;
|
|
108
|
+
for (let i = 0; next && i < pieces.length && live(); i += 1) {
|
|
109
|
+
const piece = await next;
|
|
110
|
+
next = i + 1 < pieces.length ? voice.load(pieces[i + 1], identifiers) : null;
|
|
111
|
+
if (!live()) {
|
|
112
|
+
piece.dispose();
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
currentRef.current = piece;
|
|
116
|
+
try {
|
|
117
|
+
await piece.play();
|
|
118
|
+
} finally {
|
|
119
|
+
piece.dispose();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
} catch (err) {
|
|
123
|
+
if (live()) setError(readErrorText(err));
|
|
124
|
+
} finally {
|
|
125
|
+
void (next == null ? void 0 : next.then((p) => p.dispose()).catch(() => void 0));
|
|
126
|
+
if (live()) {
|
|
127
|
+
currentRef.current = null;
|
|
128
|
+
setReadingId(null);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})();
|
|
132
|
+
}, [stop, voice]);
|
|
133
|
+
useEffect(() => () => stop(), [stop]);
|
|
134
|
+
return {
|
|
135
|
+
readingId,
|
|
136
|
+
error,
|
|
137
|
+
kind: voice.kind,
|
|
138
|
+
read,
|
|
139
|
+
stop
|
|
140
|
+
};
|
|
141
|
+
}export{cloudVoice,deviceVoice,useReadAloud};//# sourceMappingURL=readAloud.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readAloud.js","sources":["../../../src/features/dictate/readAloud.ts"],"sourcesContent":["/**\n * Reading a note or an answer aloud, through wherever the sound goes (AirPods).\n *\n * Two voices, one way of reading:\n * - the phone's own (YantraDictateVoice): nothing leaves the phone, so it says\n * what the screen shows, names included when they are shown;\n * - the connector's (YANTRA_MEETINGS_DICTATION_SPEAK), on a binary without one:\n * the hidden version only, names read as \"Name 1\". Each piece's audio comes\n * back inline, plays from the phone's cache, and is deleted after.\n *\n * Text is read in pieces; the next piece is fetched while one plays, and Stop\n * (or reading something else) cuts in at once.\n */\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { createAudioPlayer, setAudioModeAsync, type AudioPlayer } from 'expo-audio';\nimport { readErrorText, speakText, type DictateDeps } from './dictateClient';\nimport { dictateVoiceNative, type DictateVoiceNative, type SpeechEnd } from './dictateVoice';\nimport { splitForSpeech } from './speechText';\nimport type { NoteIdentifier } from './types';\n\nexport type VoiceKind = 'device' | 'cloud';\n\n/** One piece, ready to play. */\nexport interface Playable {\n /** Resolves when the piece has played or was stopped; rejects when it could not play. */\n play(): Promise<void>;\n stop(): void;\n dispose(): void;\n}\n\nexport interface Voice {\n kind: VoiceKind;\n load(text: string, identifiers: NoteIdentifier[]): Promise<Playable>;\n dispose(): void;\n}\n\nlet nextId = 0;\n\n/** The phone's own voice: speaks as soon as it is asked, ends with an event per piece. */\nexport function deviceVoice(native: DictateVoiceNative): Voice {\n const waiting = new Map<string, (state: SpeechEnd['state']) => void>();\n const sub = native.addListener('onSpeech', (event) => {\n waiting.get(event.id)?.(event.state);\n waiting.delete(event.id);\n });\n return {\n kind: 'device',\n load: async (text) => ({\n play: () =>\n new Promise<void>((resolve, reject) => {\n nextId += 1;\n const id = `dictate-${nextId}`;\n waiting.set(id, (state) =>\n state === 'error' ? reject(new Error('the phone could not speak it')) : resolve(),\n );\n native.speak(id, text, null).catch((err: unknown) => {\n waiting.delete(id);\n reject(err);\n });\n }),\n stop: () => {\n void native.stop().catch(() => undefined);\n },\n dispose: () => undefined,\n }),\n dispose: () => sub.remove(),\n };\n}\n\n/** The slice of expo-file-system (legacy API) the connector's voice needs; injectable for tests. */\nexport interface VoiceFs {\n cacheDirectory: string | null;\n writeAsStringAsync(uri: string, contents: string, options: { encoding: 'base64' }): Promise<void>;\n deleteAsync(uri: string, options?: { idempotent?: boolean }): Promise<void>;\n}\n\nfunction loadFs(): VoiceFs {\n // Lazy: the module is native, and a test or a build without it must still load this file.\n // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require\n return require('expo-file-system') as VoiceFs;\n}\n\n/** The connector's voice: each piece fetched as MP3, played from the cache, deleted after. */\nexport function cloudVoice(deps: Pick<DictateDeps, 'exec'>, files?: VoiceFs): Voice {\n return {\n kind: 'cloud',\n load: async (text, identifiers) => {\n const fs = files ?? loadFs();\n const audio = await speakText(text, identifiers, deps);\n nextId += 1;\n const uri = `${fs.cacheDirectory ?? ''}dictate-voice-${nextId}.mp3`;\n await fs.writeAsStringAsync(uri, audio, { encoding: 'base64' });\n let player: AudioPlayer | null = null;\n let ended: (() => void) | null = null;\n return {\n play: () =>\n new Promise<void>((resolve) => {\n ended = resolve;\n player = createAudioPlayer({ uri });\n player.addListener('playbackStatusUpdate', (status) => {\n if (status.didJustFinish) resolve();\n });\n player.play();\n }),\n stop: () => {\n player?.pause();\n ended?.();\n },\n dispose: () => {\n player?.remove();\n player = null;\n void fs.deleteAsync(uri, { idempotent: true }).catch(() => undefined);\n },\n };\n },\n dispose: () => undefined,\n };\n}\n\nexport interface ReadAloud {\n /** What is being read (the id given to `read`), or null. */\n readingId: string | null;\n /** Why the last reading stopped short, in words a person can act on. */\n error: string | null;\n /** The voice this phone reads with: its own, or the connector's (names hidden). */\n kind: VoiceKind;\n /**\n * Reads `textFor(kind)` aloud, after stopping anything being read.\n * `identifiers` are the dictation's placeholders, for the connector's backstop.\n */\n read(id: string, textFor: (kind: VoiceKind) => string, identifiers?: NoteIdentifier[]): void;\n stop(): void;\n}\n\nexport function useReadAloud(deps: Pick<DictateDeps, 'exec'>, makeVoice?: () => Voice): ReadAloud {\n const voice = useMemo<Voice>(() => {\n if (makeVoice) return makeVoice();\n const native = dictateVoiceNative();\n return native ? deviceVoice(native) : cloudVoice(deps);\n }, [deps, makeVoice]);\n useEffect(() => () => voice.dispose(), [voice]);\n\n const [readingId, setReadingId] = useState<string | null>(null);\n const [error, setError] = useState<string | null>(null);\n const runRef = useRef(0);\n const currentRef = useRef<Playable | null>(null);\n\n const stop = useCallback(() => {\n runRef.current += 1;\n currentRef.current?.stop();\n currentRef.current = null;\n setReadingId(null);\n }, []);\n\n const read = useCallback(\n (id: string, textFor: (kind: VoiceKind) => string, identifiers: NoteIdentifier[] = []) => {\n stop();\n runRef.current += 1;\n const run = runRef.current;\n const live = () => runRef.current === run;\n setReadingId(id);\n setError(null);\n void (async () => {\n let next: Promise<Playable> | null = null;\n try {\n // After a spoken question the session still records (call quality on AirPods): play as audio.\n await setAudioModeAsync({\n allowsRecording: false,\n playsInSilentMode: true,\n shouldPlayInBackground: false,\n }).catch(() => undefined);\n const pieces = splitForSpeech(textFor(voice.kind));\n next = pieces.length ? voice.load(pieces[0], identifiers) : null;\n for (let i = 0; next && i < pieces.length && live(); i += 1) {\n const piece: Playable = await next;\n next = i + 1 < pieces.length ? voice.load(pieces[i + 1], identifiers) : null;\n if (!live()) {\n piece.dispose();\n break;\n }\n currentRef.current = piece;\n try {\n await piece.play();\n } finally {\n piece.dispose();\n }\n }\n } catch (err) {\n if (live()) setError(readErrorText(err));\n } finally {\n // A piece fetched ahead and never played goes too.\n void next?.then((p) => p.dispose()).catch(() => undefined);\n if (live()) {\n currentRef.current = null;\n setReadingId(null);\n }\n }\n })();\n },\n [stop, voice],\n );\n\n // Leaving Dictate stops the voice.\n useEffect(() => () => stop(), [stop]);\n\n return { readingId, error, kind: voice.kind, read, stop };\n}\n"],"names":[],"mappings":"wRAiCA,IAAI,MAAS,GAAA,CAAA;AAGN,SAAS,YAAY,MAAmC,EAAA;AAC7D,EAAM,MAAA,OAAA,uBAAc,GAAiD,EAAA;AACrE,EAAA,MAAM,GAAM,GAAA,MAAA,CAAO,WAAY,CAAA,UAAA,EAAY,CAAS,KAAA,KAAA;AAtCtD,IAAA,IAAA,EAAA;AAuCI,IAAA,CAAA,EAAA,GAAA,OAAA,CAAQ,GAAI,CAAA,KAAA,CAAM,EAAE,CA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