Skip to content

Commit 388accb

Browse files
authored
「まもなく」放送がたまに再生されないバグを修正 (#5341)
1 parent 04ca13f commit 388accb

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/hooks/useTTS.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { useBusTTSText } from './useBusTTSText';
1515
import { useCachedInitAnonymousUser } from './useCachedAnonymousUser';
1616
import { useCurrentLine } from './useCurrentLine';
1717
import { usePrevious } from './usePrevious';
18+
import { useStoppingState } from './useStoppingState';
1819
import { useTTSText } from './useTTSText';
1920

2021
const BASE64_ALPHABET =
@@ -70,6 +71,8 @@ export const useTTS = (): void => {
7071
useAtomValue(speechState);
7172
const { arrived, selectedBound } = useAtomValue(stationState);
7273
const currentLine = useCurrentLine();
74+
const stoppingState = useStoppingState();
75+
const prevStoppingState = usePrevious(stoppingState);
7376

7477
const firstSpeechRef = useRef(true);
7578
// 行先選択直後の初回TTSを抑止し、発車後(arrived=false)でのみ解放する
@@ -506,6 +509,7 @@ export const useTTS = (): void => {
506509
}
507510

508511
if (!textJa || !textEn) {
512+
pendingRef.current = null;
509513
return;
510514
}
511515

@@ -515,6 +519,7 @@ export const useTTS = (): void => {
515519
firstSpeechRef,
516520
suppressFirstSpeechUntilDepartureRef,
517521
arrived,
522+
stoppingStateChanged: stoppingState !== prevStoppingState,
518523
})
519524
) {
520525
return;
@@ -536,7 +541,16 @@ export const useTTS = (): void => {
536541
console.error(err);
537542
}
538543
})();
539-
}, [arrived, enabled, prevTextEn, prevTextJa, textEn, textJa]);
544+
}, [
545+
arrived,
546+
enabled,
547+
prevStoppingState,
548+
prevTextEn,
549+
prevTextJa,
550+
stoppingState,
551+
textEn,
552+
textJa,
553+
]);
540554

541555
useEffect(() => {
542556
return () => {

src/utils/computeSuppressionDecision.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const createParams = (
66
firstSpeech: boolean;
77
suppressFirstSpeechUntilDeparture: boolean;
88
arrived: boolean;
9+
stoppingStateChanged: boolean;
910
}> = {}
1011
) => ({
1112
suppressPostFirstSpeechRef: {
@@ -16,6 +17,7 @@ const createParams = (
1617
current: overrides.suppressFirstSpeechUntilDeparture ?? false,
1718
},
1819
arrived: overrides.arrived ?? false,
20+
stoppingStateChanged: overrides.stoppingStateChanged ?? false,
1921
});
2022

2123
describe('computeSuppressionDecision', () => {
@@ -25,12 +27,21 @@ describe('computeSuppressionDecision', () => {
2527
});
2628

2729
describe('Post-first-speech 抑制', () => {
28-
it('suppressPostFirstSpeechが有効なら抑制してフラグをクリアする', () => {
30+
it('suppressPostFirstSpeechが有効でstoppingState未変化なら抑制してフラグをクリアする', () => {
2931
const params = createParams({ suppressPostFirstSpeech: true });
3032
expect(computeSuppressionDecision(params)).toBe(true);
3133
expect(params.suppressPostFirstSpeechRef.current).toBe(false);
3234
});
3335

36+
it('suppressPostFirstSpeechが有効でもstoppingStateが変化していれば抑制しない', () => {
37+
const params = createParams({
38+
suppressPostFirstSpeech: true,
39+
stoppingStateChanged: true,
40+
});
41+
expect(computeSuppressionDecision(params)).toBe(false);
42+
expect(params.suppressPostFirstSpeechRef.current).toBe(false);
43+
});
44+
3445
it('他の抑制条件より優先して評価される', () => {
3546
const params = createParams({
3647
suppressPostFirstSpeech: true,

src/utils/computeSuppressionDecision.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ export const computeSuppressionDecision = (params: {
1818
firstSpeechRef: { current: boolean };
1919
suppressFirstSpeechUntilDepartureRef: { current: boolean };
2020
arrived: boolean;
21+
stoppingStateChanged: boolean;
2122
}): boolean => {
2223
// 1. Post-first-speech: firstSpeechRef→falseで生じるテキスト変化を1回だけ無視
24+
// ただしstoppingStateが変化した場合は正当なテキスト変化なので抑止しない
2325
if (params.suppressPostFirstSpeechRef.current) {
2426
params.suppressPostFirstSpeechRef.current = false;
25-
return true;
27+
if (!params.stoppingStateChanged) {
28+
return true;
29+
}
2630
}
2731

2832
// 2. Suppress-until-departure

0 commit comments

Comments
 (0)