Skip to content

Commit 9bca01a

Browse files
authored
JR山手線でTTS文言改良 (#5375)
1 parent bcd65ed commit 9bca01a

File tree

1 file changed

+44
-20
lines changed

1 file changed

+44
-20
lines changed

src/hooks/useTTSText.ts

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@ export const useTTSText = (
4141
): [string, string] | [] => {
4242
const theme = useAtomValue(themeAtom);
4343

44-
const { selectedBound: selectedBoundOrigin, stations } =
45-
useAtomValue(stationState);
44+
const {
45+
selectedBound: selectedBoundOrigin,
46+
selectedDirection,
47+
stations,
48+
} = useAtomValue(stationState);
4649
const station = useCurrentStation();
4750
const currentLineOrigin = useCurrentLine();
4851

@@ -54,7 +57,7 @@ export const useTTSText = (
5457
const { directionalStops } = useBounds(stations);
5558
const nextStationOrigin = useNextStation();
5659
const isNextStopTerminus = useIsTerminus(nextStationOrigin);
57-
const { isLoopLine, isPartiallyLoopLine } = useLoopLine();
60+
const { isLoopLine, isPartiallyLoopLine, isYamanoteLine } = useLoopLine();
5861
const slicedStationsOrigin = useSlicedStations();
5962
const stoppingState = useStoppingState();
6063
const getStationNumberIndex = useStationNumberIndexFunc();
@@ -115,6 +118,17 @@ export const useTTSText = (
115118
[currentTrainTypeOrigin]
116119
);
117120

121+
const yamanoteTrainTypeJa = useMemo(() => {
122+
if (!isYamanoteLine || !selectedDirection) {
123+
return null;
124+
}
125+
return selectedDirection === 'INBOUND'
126+
? 'やまのて線内回り'
127+
: 'やまのて線外回り';
128+
}, [isYamanoteLine, selectedDirection]);
129+
130+
const yamanoteTrainTypeEn = isYamanoteLine ? 'Yamanote Line' : null;
131+
118132
const boundForJa = useMemo(
119133
() =>
120134
isLoopLine
@@ -283,12 +297,13 @@ export const useTTSText = (
283297
.join('、')}直通、`
284298
: ''
285299
}${
286-
currentTrainType
300+
yamanoteTrainTypeJa ??
301+
(currentTrainType
287302
? replaceJapaneseText(
288303
currentTrainType.name,
289304
currentTrainType.nameKatakana
290305
)
291-
: '各駅停車'
306+
: '各駅停車')
292307
}${boundForJa}ゆきです。${
293308
currentTrainType && afterNextStation
294309
? `${replaceJapaneseText(
@@ -371,12 +386,13 @@ export const useTTSText = (
371386
.join('、')}直通、`
372387
: ''
373388
}${
374-
currentTrainType
389+
yamanoteTrainTypeJa ??
390+
(currentTrainType
375391
? replaceJapaneseText(
376392
currentTrainType.name,
377393
currentTrainType.nameKatakana
378394
)
379-
: '各駅停車'
395+
: '各駅停車')
380396
}${boundForJa}ゆきです。`
381397
: ''
382398
}次は、${
@@ -501,10 +517,13 @@ export const useTTSText = (
501517
firstSpeech
502518
? `今日も、${
503519
currentLine.company?.nameShort
504-
}をご利用くださいまして、ありがとうございます。この電車は、${replaceJapaneseText(
505-
currentTrainType?.name,
506-
currentTrainType?.nameKatakana
507-
)}${
520+
}をご利用くださいまして、ありがとうございます。この電車は、${
521+
yamanoteTrainTypeJa ??
522+
replaceJapaneseText(
523+
currentTrainType?.name,
524+
currentTrainType?.nameKatakana
525+
)
526+
}${
508527
viaStation
509528
? `${replaceJapaneseText(
510529
viaStation.name,
@@ -626,12 +645,13 @@ export const useTTSText = (
626645
.join('、')}直通、`
627646
: ''
628647
}${
629-
currentTrainType
648+
yamanoteTrainTypeJa ??
649+
(currentTrainType
630650
? replaceJapaneseText(
631651
currentTrainType.name,
632652
currentTrainType.nameKatakana
633653
)
634-
: '各駅停車'
654+
: '各駅停車')
635655
}${boundForJa}ゆきです。${
636656
currentTrainType && afterNextStation
637657
? `${replaceJapaneseText(
@@ -698,12 +718,13 @@ export const useTTSText = (
698718
NEXT: `${
699719
firstSpeech
700720
? `この列車は${
701-
currentTrainType
721+
yamanoteTrainTypeJa ??
722+
(currentTrainType
702723
? replaceJapaneseText(
703724
currentTrainType.name,
704725
currentTrainType.nameKatakana
705726
)
706-
: '普通'
727+
: '普通')
707728
}${boundForJa}行きです。`
708729
: ''
709730
}次は${nextStation?.groupId === selectedBound?.groupId && !isLoopLine ? '終点、' : ''}${replaceJapaneseText(
@@ -758,6 +779,7 @@ export const useTTSText = (
758779
selectedBound,
759780
transferLines,
760781
viaStation,
782+
yamanoteTrainTypeJa,
761783
nextStation?.groupId,
762784
selectedBound?.groupId,
763785
]);
@@ -785,7 +807,8 @@ export const useTTSText = (
785807
}${
786808
firstSpeech
787809
? ` This train is the ${
788-
currentTrainType ? currentTrainType.nameRoman : 'Local'
810+
yamanoteTrainTypeEn ??
811+
(currentTrainType ? currentTrainType.nameRoman : 'Local')
789812
} Service on the ${
790813
currentLine.nameRoman
791814
} bound for ${boundForEn}. ${
@@ -826,7 +849,7 @@ export const useTTSText = (
826849
firstSpeech
827850
? `Thank you for using the ${
828851
currentLine.nameRoman
829-
}. This is the ${currentTrainType?.nameRoman ?? 'Local'} train ${
852+
}. This is the ${yamanoteTrainTypeEn ?? currentTrainType?.nameRoman ?? 'Local'} train ${
830853
connectedLines[0]?.nameRoman
831854
? `on the ${connectedLines[0]?.nameRoman}`
832855
: ''
@@ -957,7 +980,7 @@ export const useTTSText = (
957980
[APP_THEME.JR_WEST]: {
958981
NEXT: `${
959982
firstSpeech
960-
? `Thank you for using ${currentLine?.company?.nameEnglishShort}. This is the ${currentTrainType?.nameRoman ?? 'Local'} Service bound for ${boundForEn} ${
983+
? `Thank you for using ${currentLine?.company?.nameEnglishShort}. This is the ${yamanoteTrainTypeEn ?? currentTrainType?.nameRoman ?? 'Local'} Service bound for ${boundForEn} ${
961984
viaStation ? `via ${viaStation.nameRoman}` : ''
962985
}. We will be stopping at ${allStops
963986
.slice(0, 5)
@@ -1024,7 +1047,7 @@ export const useTTSText = (
10241047
firstSpeech
10251048
? `Thank you for using the ${currentLine.nameRoman}. `
10261049
: ''
1027-
}This is the ${currentTrainType?.nameRoman ?? 'Local'} train bound for ${boundForEn}. The next station is ${
1050+
}This is the ${yamanoteTrainTypeEn ?? currentTrainType?.nameRoman ?? 'Local'} train bound for ${boundForEn}. The next station is ${
10281051
nextStation?.nameRoman
10291052
} ${nextStationNumberText} ${
10301053
transferLines.length
@@ -1066,7 +1089,7 @@ export const useTTSText = (
10661089
ARRIVING: '',
10671090
},
10681091
[APP_THEME.JR_KYUSHU]: {
1069-
NEXT: `${firstSpeech ? `This is a ${currentTrainType?.nameRoman ?? 'Local'} train bound for ${boundForEn}.` : ''} The next station is ${
1092+
NEXT: `${firstSpeech ? `This is a ${yamanoteTrainTypeEn ?? currentTrainType?.nameRoman ?? 'Local'} train bound for ${boundForEn}.` : ''} The next station is ${
10701093
nextStation?.nameRoman
10711094
} ${nextStationNumberText}${nextStation?.groupId === selectedBound?.groupId && !isLoopLine ? ' terminal' : ''}. ${
10721095
transferLines.length
@@ -1117,6 +1140,7 @@ export const useTTSText = (
11171140
selectedBound,
11181141
transferLines,
11191142
viaStation,
1143+
yamanoteTrainTypeEn,
11201144
]);
11211145

11221146
const jaText = useMemo(() => {

0 commit comments

Comments
 (0)