feat: add tts
This commit is contained in:
13
src-tauri/Cargo.lock
generated
13
src-tauri/Cargo.lock
generated
@ -102,6 +102,7 @@ dependencies = [
|
|||||||
"tauri-plugin-fs",
|
"tauri-plugin-fs",
|
||||||
"tauri-plugin-keep-screen-on",
|
"tauri-plugin-keep-screen-on",
|
||||||
"tauri-plugin-log",
|
"tauri-plugin-log",
|
||||||
|
"tauri-plugin-tts",
|
||||||
"tauri-plugin-upload",
|
"tauri-plugin-upload",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -3875,6 +3876,18 @@ dependencies = [
|
|||||||
"time",
|
"time",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tauri-plugin-tts"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "git+https://github.com/httpjamesm/tauri-plugin-tts.git#90360c9665a1c1337ed658fcdeccc87053cb1dda"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"tauri",
|
||||||
|
"tauri-build",
|
||||||
|
"tauri-plugin",
|
||||||
|
"thiserror 2.0.12",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tauri-plugin-upload"
|
name = "tauri-plugin-upload"
|
||||||
version = "2.3.1"
|
version = "2.3.1"
|
||||||
|
|||||||
@ -26,3 +26,4 @@ tauri-plugin-log = "2"
|
|||||||
tauri-plugin-keep-screen-on = "0.1.2"
|
tauri-plugin-keep-screen-on = "0.1.2"
|
||||||
tauri-plugin-upload = "2"
|
tauri-plugin-upload = "2"
|
||||||
tauri-plugin-fs = "2"
|
tauri-plugin-fs = "2"
|
||||||
|
tauri-plugin-tts = { git = "https://github.com/httpjamesm/tauri-plugin-tts.git" }
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"upload:allow-download"
|
"upload:allow-download",
|
||||||
|
"tts:allow-speak"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -8,6 +8,12 @@
|
|||||||
<!-- AndroidTV support -->
|
<!-- AndroidTV support -->
|
||||||
<uses-feature android:name="android.software.leanback" android:required="false" />
|
<uses-feature android:name="android.software.leanback" android:required="false" />
|
||||||
|
|
||||||
|
<queries>
|
||||||
|
<intent>
|
||||||
|
<action android:name="android.intent.action.TTS_SERVICE" />
|
||||||
|
</intent>
|
||||||
|
</queries>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
|||||||
@ -4,6 +4,7 @@ pub fn run() {
|
|||||||
.plugin(tauri_plugin_fs::init())
|
.plugin(tauri_plugin_fs::init())
|
||||||
.plugin(tauri_plugin_upload::init())
|
.plugin(tauri_plugin_upload::init())
|
||||||
.plugin(tauri_plugin_keep_screen_on::init())
|
.plugin(tauri_plugin_keep_screen_on::init())
|
||||||
|
.plugin(tauri_plugin_tts::init())
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
if cfg!(debug_assertions) {
|
if cfg!(debug_assertions) {
|
||||||
app.handle().plugin(
|
app.handle().plugin(
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
import type { TextToSpeechPlugin } from "@capacitor-community/text-to-speech";
|
|
||||||
import { Capacitor } from "@capacitor/core";
|
|
||||||
import { duck, unduck } from "tauri-plugin-duck-api";
|
import { duck, unduck } from "tauri-plugin-duck-api";
|
||||||
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
|
|
||||||
export let tts: TextToSpeechPlugin | "web" | null = null;
|
export let tts: "tauri" | "web" | null = null;
|
||||||
|
|
||||||
export async function initTTS() {
|
export async function initTTS() {
|
||||||
if (Capacitor.isNativePlatform()) {
|
if (window.__TAURI__) {
|
||||||
console.log("Using Capacitor TTS");
|
console.log("Using Tauri TTS");
|
||||||
tts = (await import("@capacitor-community/text-to-speech")).TextToSpeech;
|
tts = "tauri";
|
||||||
} else {
|
} else {
|
||||||
console.log("Using Web TTS");
|
console.log("Using Web TTS");
|
||||||
tts = "web";
|
tts = "web";
|
||||||
@ -24,10 +23,7 @@ export default async function say(text: string) {
|
|||||||
duck();
|
duck();
|
||||||
if (tts !== "web") {
|
if (tts !== "web") {
|
||||||
try {
|
try {
|
||||||
await tts?.speak({
|
await invoke("plugin:tts|speak", { text })
|
||||||
text: text,
|
|
||||||
lang: "deu-default", // TODO: make this configurable
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error speaking text", e);
|
console.error("Error speaking text", e);
|
||||||
alert(e);
|
alert(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user