Repository navigation
feat(mobile): pick the language voice input transcribes in #22380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c956f0
feat(mobile): voice input can transcribe in a chosen language
GSTJ c78c6a2
feat(mobile): pick the dictation language in Settings
GSTJ c972b13
fix(mobile): keep Device language after other preference saves
GSTJ 40b2040
feat(mobile): native transcription module lists the languages the dev…
GSTJ 7b354f9
feat(mobile): dictation language picker lists what the device supports
GSTJ 564d1a4
Merge remote-tracking branch 'upstream/main' into feat/voice-transcri…
GSTJ 546c05a
fix(mobile): preserve dictation language extensions
GSTJ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
apps/mobile/src/features/settings/SettingsDictationLanguageRouteScreen.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView"; | ||
| import { useAtomSet, useAtomValue } from "@effect/atom-react"; | ||
| import { AsyncResult } from "effect/reactivity"; | ||
| import { View } from "react-native"; | ||
| import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||
|
|
||
| import { | ||
| DEVICE_DICTATION_LANGUAGE_LABEL, | ||
| useDictationLanguages, | ||
| } from "../../lib/dictationLanguages"; | ||
| import { mobilePreferencesAtom, updateMobilePreferencesAtom } from "../../state/preferences"; | ||
| import { SettingsChoiceRow } from "./components/SettingsChoiceRow"; | ||
| import { SettingsSection } from "./components/SettingsSection"; | ||
|
|
||
| export function SettingsDictationLanguageRouteScreen() { | ||
| const insets = useSafeAreaInsets(); | ||
| const preferencesResult = useAtomValue(mobilePreferencesAtom); | ||
| const savePreferences = useAtomSet(updateMobilePreferencesAtom); | ||
| const preferencesReady = AsyncResult.isSuccess(preferencesResult) && !preferencesResult.waiting; | ||
| const selectedId = AsyncResult.isSuccess(preferencesResult) | ||
| ? (preferencesResult.value.voiceInputLocale ?? null) | ||
| : undefined; | ||
| const languages = useDictationLanguages(); | ||
| const options = [{ id: null, label: DEVICE_DICTATION_LANGUAGE_LABEL }, ...(languages ?? [])]; | ||
|
|
||
| return ( | ||
| <View collapsable={false} className="flex-1 bg-sheet"> | ||
| <ScrollView | ||
| contentInsetAdjustmentBehavior="automatic" | ||
| showsVerticalScrollIndicator={false} | ||
| className="flex-1" | ||
| contentContainerClassName="gap-3 px-5 pt-4" | ||
| contentContainerStyle={{ paddingBottom: Math.max(insets.bottom, 18) + 18 }} | ||
| > | ||
| <SettingsSection | ||
| footer={ | ||
| languages?.length === 0 | ||
| ? "This device has no dictation languages to choose from." | ||
| : "The language you speak when dictating." | ||
| } | ||
| > | ||
| {options.map((option, index) => ( | ||
| <SettingsChoiceRow | ||
| key={option.id ?? "device"} | ||
| label={option.label} | ||
| selected={selectedId === option.id} | ||
| separated={index > 0} | ||
| disabled={!preferencesReady} | ||
| onPress={() => savePreferences({ voiceInputLocale: option.id })} | ||
| /> | ||
| ))} | ||
| </SettingsSection> | ||
| </ScrollView> | ||
| </View> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { dictationLanguageLabel } from "./dictationLanguages"; | ||
|
|
||
| const languages = [{ id: "pt-BR", label: "Português (Brasil)" }]; | ||
|
|
||
| describe("dictationLanguageLabel", () => { | ||
| it("names the chosen language from the loaded list", () => { | ||
| expect(dictationLanguageLabel(languages, "pt-BR")).toBe("Português (Brasil)"); | ||
| }); | ||
|
|
||
| it("shows the raw tag until the list loads or when the list lacks it", () => { | ||
| expect(dictationLanguageLabel(undefined, "pt-BR")).toBe("pt-BR"); | ||
| expect(dictationLanguageLabel(languages, "sv-SE")).toBe("sv-SE"); | ||
| }); | ||
|
|
||
| it("names the device language when nothing is chosen", () => { | ||
| expect(dictationLanguageLabel(languages, null)).toBe("Device language"); | ||
| expect(dictationLanguageLabel(undefined, undefined)).toBe("Device language"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| import { getDictationLanguages } from "../native/voiceTranscription"; | ||
| import type { DictationLanguage } from "../native/voiceTranscription.types"; | ||
|
|
||
| export const DEVICE_DICTATION_LANGUAGE_LABEL = "Device language"; | ||
|
|
||
| /** The languages this device can transcribe, or undefined while they load. */ | ||
| export function useDictationLanguages(): ReadonlyArray<DictationLanguage> | undefined { | ||
| const [languages, setLanguages] = useState<ReadonlyArray<DictationLanguage>>(); | ||
| // oxlint-disable-next-line t3code/react-effect-budget -- Load the native device capabilities when this screen mounts. | ||
| useEffect(() => { | ||
| let cancelled = false; | ||
| getDictationLanguages().then( | ||
| (loaded) => { | ||
| if (!cancelled) setLanguages(loaded); | ||
| }, | ||
| () => { | ||
| if (!cancelled) setLanguages([]); | ||
| }, | ||
| ); | ||
| return () => { | ||
| cancelled = true; | ||
| }; | ||
| }, []); | ||
| return languages; | ||
| } | ||
|
|
||
| export function dictationLanguageLabel( | ||
| languages: ReadonlyArray<DictationLanguage> | undefined, | ||
| id: string | null | undefined, | ||
| ): string { | ||
| if (id == null) return DEVICE_DICTATION_LANGUAGE_LABEL; | ||
| return languages?.find((language) => language.id === id)?.label ?? id; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| import type { VoiceTranscriber } from "@t3tools/client-runtime/voice-input"; | ||
|
|
||
| export function getLocalVoiceTranscriber(): VoiceTranscriber | null { | ||
| import type { DictationLanguage } from "./voiceTranscription.types"; | ||
|
|
||
| export function getLocalVoiceTranscriber(_preferredLocale?: string): VoiceTranscriber | null { | ||
| return null; | ||
| } | ||
|
|
||
| export function getDictationLanguages(): Promise<ReadonlyArray<DictationLanguage>> { | ||
| return Promise.resolve([]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export interface DictationLanguage { | ||
| readonly id: string; | ||
| readonly label: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.