I'm currently developing an app which has to get real-time information about the current pitch. Since I already build a website with the same function, I'm am using react-native with expo.
For pitch detection I use the following libary: https://github.com/qiuxiang/react-native-tuner which is build ontop of https://www.npmjs.com/package/react-native-recording .
Unfortunatly after calling Recording.init() inside the tuner class I get following error
[Unhandled promise rejection: TypeError: Cannot read property 'init' of undefined]
The code in this class looks like this:
import Recording from "react-native-recording";
import PitchFinder from "pitchfinder";
export default class Tuner {
...
constructor(sampleRate = 22050, bufferSize = 2048) {
this.sampleRate = sampleRate;
this.bufferSize = bufferSize;
this.pitchFinder = new PitchFinder.YIN({ sampleRate: this.sampleRate });
}
start() {
Recording.init({
sampleRate: this.sampleRate,
bufferSize: this.bufferSize,
});
...
The tuner class is initialized here, so I should have permission to access the microphone after the prompt on the device:
...
async componentDidMount() {
if (Platform.OS === "android") {
await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.RECORD_AUDIO,
]);
}
const tuner = new Tuner();
...
I have no idea on how to fix that since this is my first react-native app. Would gladly appreciate any help!
I figured that react-native libarys are not compatible with expo. Changed my project to a react-native one and it worked just fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.