feat(routing): detect TTS language from valhalla trip

This commit is contained in:
2025-10-02 21:41:03 +02:00
parent 26b1fbc60c
commit 920681f68c
4 changed files with 27 additions and 7 deletions

View File

@ -160,5 +160,9 @@
"poi": { "poi": {
"fuel": "Tankstelle", "fuel": "Tankstelle",
"parking": "Parken" "parking": "Parken"
},
"routing": {
"off-route": "Sie sind von der Route abgekommen",
"back-on-route": "Sie sind wieder auf der Route"
} }
} }

View File

@ -160,5 +160,9 @@
"poi": { "poi": {
"fuel": "Fuel Station", "fuel": "Fuel Station",
"parking": "Parking" "parking": "Parking"
},
"routing": {
"off-route": "You went off route",
"back-on-route": "You are back on route"
} }
} }

View File

@ -1,6 +1,7 @@
import { duck, unduck } from "tauri-plugin-duck-api"; import { duck, unduck } from "tauri-plugin-duck-api";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
import { m } from "$lang/messages"; import { m } from "$lang/messages";
import { locales, type Locale } from "$lang/runtime";
export let tts: "tauri" | "web" | null = null; export let tts: "tauri" | "web" | null = null;
@ -14,7 +15,15 @@ export async function initTTS() {
} }
} }
export default async function say(text: string) { export function findLocaleForValhallaLanguage(language: string) {
for(const locale of locales) {
if(m["language.valhalla"]({ language }, { locale }) === language) {
return locale;
}
}
}
export default async function say(text: string, language?: Locale) {
if (!tts) { if (!tts) {
// alert("TTS not initialized"); // alert("TTS not initialized");
// console.error("TTS not initialized"); // console.error("TTS not initialized");
@ -24,7 +33,7 @@ export default async function say(text: string) {
duck(); duck();
if (tts !== "web") { if (tts !== "web") {
try { try {
await invoke("plugin:tts|speak", { text, language: m["language.tts"]() }); await invoke("plugin:tts|speak", { text, language: language ? m["language.tts"]({}, { locale: language }) : m["language.tts"]() });
} catch (e) { } catch (e) {
console.error("Error speaking text", e); console.error("Error speaking text", e);
alert(e); alert(e);

View File

@ -1,10 +1,11 @@
import { location } from "$lib/components/lnv/location.svelte"; import { location } from "$lib/components/lnv/location.svelte";
import { map } from "$lib/components/lnv/map.svelte"; import { map } from "$lib/components/lnv/map.svelte";
import say from "./TTS"; import say, { findLocaleForValhallaLanguage } from "./TTS";
import type { ValhallaRequest } from "./ValhallaRequest"; import type { ValhallaRequest } from "./ValhallaRequest";
import type { LngLatBoundsLike } from "maplibre-gl"; import type { LngLatBoundsLike } from "maplibre-gl";
import { generateVoiceGuidance } from "./VoiceGuidance"; import { generateVoiceGuidance } from "./VoiceGuidance";
import { keepScreenOn } from "tauri-plugin-keep-screen-on-api"; import { keepScreenOn } from "tauri-plugin-keep-screen-on-api";
import { m } from "$lang/messages";
export const routing = $state({ export const routing = $state({
geojson: { geojson: {
@ -180,14 +181,14 @@ async function tickRoute() {
if (!isOnShape(loc, polyline)) { if (!isOnShape(loc, polyline)) {
console.log("Off route!"); console.log("Off route!");
if (!info.isOffRoute) { if (!info.isOffRoute) {
say("You went off route."); say(m["routing.off-route"]());
} }
info.isOffRoute = true; info.isOffRoute = true;
// TODO: Implement re-routing logic // TODO: Implement re-routing logic
return; return;
} else { } else {
if (info.isOffRoute) { if (info.isOffRoute) {
say("You are back on route."); say(m["routing.back-on-route"]());
} }
info.isOffRoute = false; info.isOffRoute = false;
} }
@ -212,7 +213,8 @@ async function tickRoute() {
// currentManeuver.verbal_pre_transition_instruction, // currentManeuver.verbal_pre_transition_instruction,
instruction, instruction,
); );
say(instruction); const locale = findLocaleForValhallaLanguage(trip.language);
say(instruction, locale);
} }
} }
@ -244,7 +246,8 @@ async function tickRoute() {
"[Verbal instruction] ", "[Verbal instruction] ",
currentManeuver.verbal_post_transition_instruction, currentManeuver.verbal_post_transition_instruction,
); );
say(currentManeuver.verbal_post_transition_instruction); const locale = findLocaleForValhallaLanguage(trip.language);
say(currentManeuver.verbal_post_transition_instruction, locale);
} }
} }