Anonymous
Речь к тексту в React Native
Сообщение
Anonymous » 20 фев 2025, 08:40
Итак, я пытаюсь построить речь к текстовому приложению в React-Contive для Android, я использую React-C-woudio-Recorder-Player Libary для записи и для хранения RNF, звук сохраняет в этом месте, но голос является Не придет, код приведен ниже < /p>
Код: Выделить всё
import RNFS from 'react-native-fs';
import AudioRecorderPlayer, {
AVEncoderAudioQualityIOSType,
AVEncodingOption,
AVModeIOSOption,
AudioEncoderAndroidType,
AudioSourceAndroidType,
OutputFormatAndroidType,
} from 'react-native-audio-recorder-player';
import { useState } from 'react';
import { Platform } from 'react-native';
const audioRecorderPlayer = new AudioRecorderPlayer();
audioRecorderPlayer.setSubscriptionDuration(0.1);
const useRecording = () => {
const [recording, setRecording] = useState(false);
const [recordingPath, setRecordingPath] = useState('');
const audioSet = {
AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
AudioSourceAndroid: AudioSourceAndroidType.MIC,
AVModeIOS: AVModeIOSOption.measurement,
AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,
AVNumberOfChannelsKeyIOS: 2,
AVFormatIDKeyIOS: AVEncodingOption.aac,
OutputFormatAndroid: OutputFormatAndroidType.AAC_ADTS,
};
const startRecording = async () => {
const dirs =
Platform.OS === 'ios'
? RNFS.DocumentDirectoryPath
: RNFS.ExternalDirectoryPath;
console.log('dir', dirs);
const path = Platform.select({
ios: `${dirs}hello.m4a`,
android: `${dirs}/hello.wav`,
}); // File name for your recording
console.log('Recorded File Path:', path);
const result = await audioRecorderPlayer.startRecorder(
path,
audioSet,
true,
);
console.log('result', result);
setRecording(true);
setRecordingPath(result);
};
const stopRecording = async () => {
const result = await audioRecorderPlayer.stopRecorder();
setRecording(false);
};
return {
startRecording,
stopRecording,
setRecording,
recording,
recordingPath,
}
};
export default useRecording;
Я попробовал, что звук не появится, я ожидаю прослушать аудио
Подробнее здесь:
https://stackoverflow.com/questions/794 ... act-native
1740030000
Anonymous
Итак, я пытаюсь построить речь к текстовому приложению в React-Contive для Android, я использую React-C-woudio-Recorder-Player Libary для записи и для хранения RNF, звук сохраняет в этом месте, но голос является Не придет, код приведен ниже < /p> [code] import RNFS from 'react-native-fs'; import AudioRecorderPlayer, { AVEncoderAudioQualityIOSType, AVEncodingOption, AVModeIOSOption, AudioEncoderAndroidType, AudioSourceAndroidType, OutputFormatAndroidType, } from 'react-native-audio-recorder-player'; import { useState } from 'react'; import { Platform } from 'react-native'; const audioRecorderPlayer = new AudioRecorderPlayer(); audioRecorderPlayer.setSubscriptionDuration(0.1); const useRecording = () => { const [recording, setRecording] = useState(false); const [recordingPath, setRecordingPath] = useState(''); const audioSet = { AudioEncoderAndroid: AudioEncoderAndroidType.AAC, AudioSourceAndroid: AudioSourceAndroidType.MIC, AVModeIOS: AVModeIOSOption.measurement, AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high, AVNumberOfChannelsKeyIOS: 2, AVFormatIDKeyIOS: AVEncodingOption.aac, OutputFormatAndroid: OutputFormatAndroidType.AAC_ADTS, }; const startRecording = async () => { const dirs = Platform.OS === 'ios' ? RNFS.DocumentDirectoryPath : RNFS.ExternalDirectoryPath; console.log('dir', dirs); const path = Platform.select({ ios: `${dirs}hello.m4a`, android: `${dirs}/hello.wav`, }); // File name for your recording console.log('Recorded File Path:', path); const result = await audioRecorderPlayer.startRecorder( path, audioSet, true, ); console.log('result', result); setRecording(true); setRecordingPath(result); }; const stopRecording = async () => { const result = await audioRecorderPlayer.stopRecorder(); setRecording(false); }; return { startRecording, stopRecording, setRecording, recording, recordingPath, } }; export default useRecording; [/code] Я попробовал, что звук не появится, я ожидаю прослушать аудио Подробнее здесь: [url]https://stackoverflow.com/questions/79453433/speech-to-text-in-react-native[/url]