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": {
"fuel": "Tankstelle",
"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": {
"fuel": "Fuel Station",
"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 { invoke } from "@tauri-apps/api/core";
import { m } from "$lang/messages";
import { locales, type Locale } from "$lang/runtime";
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) {
// alert("TTS not initialized");
// console.error("TTS not initialized");
@ -24,7 +33,7 @@ export default async function say(text: string) {
duck();
if (tts !== "web") {
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) {
console.error("Error speaking text", e);
alert(e);

View File

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