react native 에서 음성 파일을 쓰려면
react-native-sound 를 사용한다
import Sound from 'react-native-sound';
const sound = new Sound('sound.mp3', Sound.MAIN_BUNDLE, error => {
if (error) {
console.log('failed to load the sound', error);
return;
}
// loaded successfully
console.log(
'duration in seconds: ' +
sound.getDuration() +
'number of channels: ' +
sound.getNumberOfChannels(),
);
// Play the sound with an onEnd callback
sound.play(success => {
if (success) {
console.log('successfully finished playing');
} else {
console.log('playback failed due to audio decoding errors');
}
});
});
ios 의 경우 XCode 의 project 명으로 된 최상위 폴더에 우클릭을 하여
Add Files to "[project 명]" 을 선택 후 음성 파일을 선택하여 추가한다