Vlad Narizhnyi
10 months ago
28 changed files with 279 additions and 44 deletions
Binary file not shown.
Binary file not shown.
@ -1 +1,2 @@
@@ -1 +1,2 @@
|
||||
export * from './package-name.config'; |
||||
export * from './voice.config'; |
||||
|
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
import { Language } from '~module/common' |
||||
|
||||
export const voiceConfig: any = { |
||||
[Language.UA]: { |
||||
language: 'uk-UA', |
||||
voice: 'com.apple.voice.compact.uk-UA.Lesya', |
||||
}, |
||||
[Language.EN]: { |
||||
language: 'en-US', |
||||
voice: 'com.apple.ttsbundle.Samantha-compact', |
||||
}, |
||||
} |
@ -1,2 +1,3 @@
@@ -1,2 +1,3 @@
|
||||
export * from './get-current-truth-dares.hook' |
||||
export * from './use-set-steps-by-package'; |
||||
export * from './use-voice.hook'; |
||||
|
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
import { useEffect, useState } from 'react' |
||||
import Tts from 'react-native-tts' |
||||
import { voiceConfig } from '../config' |
||||
import { useTranslation } from 'react-i18next' |
||||
import { StorageKey, storageService } from '~module/common' |
||||
|
||||
export const useVoice = () => { |
||||
const { i18n } = useTranslation() |
||||
const [ttsStatus, setTtsStatus] = useState('initiliazing') |
||||
|
||||
useEffect(() => { |
||||
Tts.addEventListener('tts-start', _event => setTtsStatus('started')) |
||||
Tts.addEventListener('tts-finish', _event => setTtsStatus('finished')) |
||||
Tts.addEventListener('tts-cancel', _event => setTtsStatus('cancelled')) |
||||
Tts.getInitStatus().then(initTts) |
||||
|
||||
return () => { |
||||
Tts.removeEventListener('tts-start', _event => |
||||
setTtsStatus('started'), |
||||
) |
||||
Tts.removeEventListener('tts-finish', _event => |
||||
setTtsStatus('finished'), |
||||
) |
||||
Tts.removeEventListener('tts-cancel', _event => |
||||
setTtsStatus('cancelled'), |
||||
) |
||||
} |
||||
}, []) |
||||
|
||||
const initTts = async () => { |
||||
try { |
||||
await Tts.setDefaultLanguage(voiceConfig[i18n.language].language) |
||||
await Tts.setDefaultVoice(voiceConfig[i18n.language].voice) |
||||
await Tts.setDefaultRate(0.5) |
||||
} catch (err) { |
||||
//Samsung S9 has always this error:
|
||||
//"Language is not supported"
|
||||
console.log(`setDefaultLanguage error `, err) |
||||
} |
||||
setTtsStatus('initialized') |
||||
} |
||||
} |
@ -1,3 +1,4 @@
@@ -1,3 +1,4 @@
|
||||
export * from './selected-language-in-settings.atom' |
||||
export * from './switch-notifications.atom' |
||||
export * from './purchases.atom' |
||||
export * from './switch-voiceover.atom'; |
||||
|
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
import React, { useEffect, useState } from 'react' |
||||
import { Switch } from 'react-native' |
||||
import { StorageKey, colors, storageService } from '../../common' |
||||
|
||||
export const SwitchVoiceoverAtom = () => { |
||||
const [voiceover, setVoiceover] = useState(true) |
||||
|
||||
const toggleSwitch = async () => { |
||||
setVoiceover(!voiceover) |
||||
await storageService.set(StorageKey.Voiceover, !voiceover) |
||||
} |
||||
|
||||
const getIsVoiceover = async () => { |
||||
const isVoiceover = await storageService.get(StorageKey.Voiceover) |
||||
|
||||
setVoiceover(isVoiceover) |
||||
} |
||||
|
||||
useEffect(() => { |
||||
getIsVoiceover() |
||||
}, []) |
||||
|
||||
return ( |
||||
<Switch |
||||
trackColor={{ true: colors.purple }} |
||||
thumbColor={voiceover ? colors.turquoise : colors.darkPurple} |
||||
ios_backgroundColor={colors.purple} |
||||
onValueChange={toggleSwitch} |
||||
style={{ width: 51 }} |
||||
value={voiceover} |
||||
/> |
||||
) |
||||
} |
Loading…
Reference in new issue