Код: Выделить всё
const ApptSummary: React.FC\
= ({ navigation }): JSX.Element =\> {
const [index, setIndex] = useState(0);
const renderScene = SceneMap({
third: () => ,
fourth: () => ,
});
const [routes] = React.useState([
{ key: 'third', title: 'Pre-Diagnosis' },
{ key: 'fourth', title: 'Physician Diagnosis' },
]);
const renderTabBar = props => (
(
{route.title}
)}
/>
);
return (
\
\
);
}
const ApptPrediagnosisNotes: React.FC = ({ }): JSX.Element =\> {
const \[text1, setText1\] = useState('');
useEffect(() =\>
{
requestMicrophonePermission();
Voice.destroy().then(speechInstance.removeAllListeners);
Voice.onSpeechStart = e =\> console.log('onSpeechStart:', e);
Voice.onSpeechEnd = e =\> {
console.log('onSpeechEnd:', e);
setIsListening1(false);
Код: Выделить всё
speechInstance.onSpeechError = e =\> console.log('onSpeechError:', e);
Voice.onSpeechResults = e =\> {
const latestSpeechResult = e.value\[0\];
setInput((prevInput1) =\> prevInput1.includes(latestSpeechResult) ?
prevInput1 : ${prevInput1} ${latestSpeechResult}.trim());
setText1((prevText1) =\> prevText1.includes(latestSpeechResult) ?
prevText1 : ${prevText1} ${latestSpeechResult}.trim());
console.log('the latest is : ' + text1)
Код: Выделить всё
return () => {
Voice.destroy().then(speechInstance.removeAllListeners);
};
}, \[\]);
const startListening1 = async () =\> {
try {
setIsListening1(true);
await Voice.start('en-US');
catch (e) {
console.error('Error in startListening:', e);
setIsListening1(false);
}
};
const stopListening1 = async () =\> {
try
{
await Voice.stop();
setIsListening1(false);
}
catch (e) {
console.error('Error in stopListening:', e);
}
};
return(
\
\
\
{isListening1 ? 'Stop Listening' : 'Start Speaking'}\
\
handleText(newText)}
placeholder="Type here.."
placeholderTextColor={'#ccc'}
/>
)
}
const PhysicianDiagnosis: React.FC = ({ }): JSX.Element =\> {
useEffect(() =\> {
requestMicrophonePermission();
Voice.destroy().then(Voice.removeAllListeners);
Voice.onSpeechStart = e => {
console.log('onSpeechStart:', e);
};
Voice.onSpeechEnd = e => {
console.log('onSpeechEnd:', e);
startListening();
};
Voice.onSpeechError = e => console.log('onSpeechError:', e);
Voice.onSpeechResults = e => {
console.log('onSpeechResults:', e.value);
const latestSpeechResult = e.value[0];
setText((prevText) => prevText.includes(latestSpeechResult) ?
prevText : `${prevText} ${latestSpeechResult}`.trim());
setInput((prevInput) => prevInput.includes(latestSpeechResult) ?
prevInput : `${prevInput} ${latestSpeechResult}`.trim());
console.log('Stored speech:', latestSpeechResult);
};
return () => {
Voice.destroy().then(Voice.removeAllListeners);
};
}, \[\]);
const startListening = async () =\> {
try
{
setIsListening2(true);
await Voice.start('en-US');
} catch (e) {
console.error('Error in startListening:', e);
setIsListening2(false);
}
};
const stopListening = async () =\> {
try
{
await Voice.stop();
setIsListening2(false);
Код: Выделить всё
catch (e) {
console.error('Error in stopListening:', e);
}
};
return (
\
\
\
{isListening2 ? 'Stop Listening' : 'Start Speaking'}\
\
\ setText(newText)}
placeholder="Speak or type here"
Код: Выделить всё
\
В приведенном выше коде я пытаюсь записать голос и преобразовать его в текст с помощью реакции-native-voice/ голос. Всякий раз, когда я записываю голос при диагностике врача, он работает правильно, а когда я начинаю записывать голос при предварительной диагностике, он не показывает преобразованную речь в текст, а вместо этого отображается на консоли диагностики врача. Попробовал изменить экземпляры, но не помогло.
Руководство любого было бы очень полезно.
Заранее спасибо
Подробнее здесь: https://stackoverflow.com/questions/790 ... view-and-r