Make text-to-speech reliable on Android
Do not treat a not-yet-loaded voice list as missing German voice, poll for voices, wait after cancel before speaking, keep utterances referenced, retry stalled speech, detect missing end events, unlock speech on first tap, and stop the microphone before the examiner speaks.
This commit is contained in:
1 parent
c754477f07
commit
5d760c0bf6
5 files changed
+193
-47
No files matched your search
+2
-2
@@ -6,7 +6,7 @@ import Quiz from "@/components/Quiz";
|
||||
import ResultCard from "@/components/ResultCard";
|
||||
import Ar from "@/components/Ar";
|
||||
import { recordResult, useProgress } from "@/lib/progress";
|
||||
import { hasGermanVoice, speakSequence, stopSpeaking, TTS_MISSING_EVENT, ttsSupported } from "@/lib/speech";
|
||||
import { germanVoiceMissing, speakSequence, stopSpeaking, TTS_MISSING_EVENT, ttsSupported } from "@/lib/speech";
|
||||
|
||||
export default function HoerenPage() {
|
||||
const [teil, setTeil] = useState<number>(1);
|
||||
@@ -92,7 +92,7 @@ function Player({ item, onBack }: { item: HoerItem; onBack: () => void }) {
|
||||
return;
|
||||
}
|
||||
if (exam && plays >= maxPlays) return;
|
||||
if (!hasGermanVoice()) {
|
||||
if (germanVoiceMissing()) {
|
||||
window.dispatchEvent(new Event(TTS_MISSING_EVENT));
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
return;
|
||||
|
||||
@@ -10,7 +10,7 @@ import type { Question } from "@/data/types";
|
||||
import Quiz from "@/components/Quiz";
|
||||
import Ar from "@/components/Ar";
|
||||
import { recordResult } from "@/lib/progress";
|
||||
import { hasGermanVoice, speakSequence, stopSpeaking, TTS_MISSING_EVENT } from "@/lib/speech";
|
||||
import { germanVoiceMissing, speakSequence, stopSpeaking, TTS_MISSING_EVENT } from "@/lib/speech";
|
||||
import { fireConfetti } from "@/components/AppShell";
|
||||
import { sfx } from "@/lib/sfx";
|
||||
|
||||
@@ -266,7 +266,7 @@ function ExamAudio({ item }: { item: HoerItem }) {
|
||||
className="btn blue"
|
||||
disabled={playing || plays >= max}
|
||||
onClick={() => {
|
||||
if (!hasGermanVoice()) {
|
||||
if (germanVoiceMissing()) {
|
||||
window.dispatchEvent(new Event(TTS_MISSING_EVENT));
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
return;
|
||||
|
||||
@@ -323,6 +323,11 @@ function SessionView({ session, onBack }: { session: Session; onBack: () => void
|
||||
const text = (textRaw ?? input).trim();
|
||||
if (!text || done) return;
|
||||
stopSpeaking();
|
||||
// Mikrofon aus, bevor der Prüfer antwortet – sonst blockiert es auf Android die Sprachausgabe
|
||||
// (und würde die Stimme des Prüfers mitschreiben).
|
||||
stopRef.current?.();
|
||||
stopRef.current = null;
|
||||
setListening(false);
|
||||
setInput("");
|
||||
const mine: Msg = { from: "me", de: text };
|
||||
const history = [...msgs, mine];
|
||||
|
||||
Reference in new issue
Block a user