feat(routing): detect TTS language from valhalla trip
This commit is contained in:
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user