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-keep-screen-on",
|
||||
"tauri-plugin-log",
|
||||
"tauri-plugin-tts",
|
||||
"tauri-plugin-upload",
|
||||
]
|
||||
|
||||
@ -3875,6 +3876,18 @@ dependencies = [
|
||||
"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]]
|
||||
name = "tauri-plugin-upload"
|
||||
version = "2.3.1"
|
||||
|
||||
@ -26,3 +26,4 @@ tauri-plugin-log = "2"
|
||||
tauri-plugin-keep-screen-on = "0.1.2"
|
||||
tauri-plugin-upload = "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 -->
|
||||
<uses-feature android:name="android.software.leanback" android:required="false" />
|
||||
|
||||
<queries>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.TTS_SERVICE" />
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
||||
@ -4,6 +4,7 @@ pub fn run() {
|
||||
.plugin(tauri_plugin_fs::init())
|
||||
.plugin(tauri_plugin_upload::init())
|
||||
.plugin(tauri_plugin_keep_screen_on::init())
|
||||
.plugin(tauri_plugin_tts::init())
|
||||
.setup(|app| {
|
||||
if cfg!(debug_assertions) {
|
||||
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 { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
export let tts: TextToSpeechPlugin | "web" | null = null;
|
||||
export let tts: "tauri" | "web" | null = null;
|
||||
|
||||
export async function initTTS() {
|
||||
if (Capacitor.isNativePlatform()) {
|
||||
console.log("Using Capacitor TTS");
|
||||
tts = (await import("@capacitor-community/text-to-speech")).TextToSpeech;
|
||||
if (window.__TAURI__) {
|
||||
console.log("Using Tauri TTS");
|
||||
tts = "tauri";
|
||||
} else {
|
||||
console.log("Using Web TTS");
|
||||
tts = "web";
|
||||
@ -24,10 +23,7 @@ export default async function say(text: string) {
|
||||
duck();
|
||||
if (tts !== "web") {
|
||||
try {
|
||||
await tts?.speak({
|
||||
text: text,
|
||||
lang: "deu-default", // TODO: make this configurable
|
||||
});
|
||||
await invoke("plugin:tts|speak", { text })
|
||||
} catch (e) {
|
||||
console.error("Error speaking text", e);
|
||||
alert(e);
|
||||
|
||||
Reference in New Issue
Block a user