In React native, when I start speech recognition it gives beep sound.
Code that I used to start recognition :
_startRecognizing = async() => {
try {
await Voice.start();
} catch (e) {
console.log(e);
}
};
Library used : https://github.com/react-native-community/react-native-voice
Is there any way to mute this Beep sound in android?
There seems to be no solution to this request yet
See here
Related
I am using both react-native-voice and expo-speech libraries to transcript my voice and to convert a text to a speech. The problem is, when i end registering my voice and start a speech with expo-voice, there is no sound. It seems like react-native-voice completly mutes the audio when the voice recording is ended. The speech starts, but i must press on the mic button (activating the voice recognition) to hear it.
The only way i found to make everything work together is by stopping the voice recording after the text to speech has ended. Here is a part of the code :
const startRecognizing = async () => {
setButtonColor('#38b000');
// Starts listening for speech for a specific locale
try {
await Voice.start('en-EN');
} catch (e) {
console.error(e);
}
};
const destroyRecognizer = async () => {
//Destroys the current SpeechRecognizer instance
try {
await Voice.destroy();
} catch (e) {
console.error(e);
}
};
const stopRecognizing = async () => {
setButtonColor('#344E41');
setTimeout(() => {
Speech.speak("I did not understand, can you repeat please ?", {
language: 'en-EN',
onDone: () => {
setTimeout(
async() => {
await destroyRecognizer();
}, 1000);
},
});
}, 1000);
};
return (
<View style={styles.microphoneButtonContainer}>
<TouchableOpacity
onPressIn={startRecognizing}
onPressOut={stopRecognizing}>
<Image
style={styles.microphoneButton}
source={require('../img/microphone-icon.png')}
/>
</TouchableOpacity>
</View>
);
This solution brings a lot of edgecases so i can't work with it. None of the methods given to stop the recording solve the issue. And i did not found any help in the libraries docs. Is there a solution to this ? Thank you for your help !
Because there was no way to solve the issue with react-native-voice methods, i had the idea to go search directly in the library if i can modify the native code. For ios the code is in ios/voice/Voice.m. I found this :
- (void) teardown {
self.isTearingDown = YES;
[self.recognitionTask cancel];
self.recognitionTask = nil;
// Set back audio session category
[self resetAudioSession];
So i tried to comment out [self resetAudioSession];, i then rebuilt the packages with npx-pod-install (i use cocoapod), and it worked!
Doing this may cause edgecases, i did not fully test the methods yet, and i did not try for android.
I want to play a sound when I get new data from firebase firestore. It doesn't matter whether screen is on or off, but sound must play in the background when I get data (like a telephone ring) (app will be on). Which library will be the best to achieve it ? plz help me to choose.. My project is in react native
Firestore's collection provides an event listener when new data is added, updated, or deleted.
collection.onSnapshot(
(querySnapshot) => {
querySnapshot.docChanges().forEach((change) => {
if (change.type === "added") {
// Handle new added data
// Play sound logic here
}
if (change.type === "modified") {
}
if (change.type === "removed") {
}
});
},
(err) => {
console.log(`Encountered error: ${err}`);
}
);
I'm a beginner at React Native.
I am trying to access a native(built-in) camera app on Android device.
I used React-Native-Image-Picker to open the camera app but I would like to record a video somehow automatically(?) I mean not using my finger.
I need codes that make it to record and stop the video.
(I don't mean to give me a code rather, please advise if it is even possible?)
Any help would be very appreciated.
Thank you!
It is possible.
Package: https://github.com/mrousavy/react-native-vision-camera
Review the API and Guide section to see how to start and stop recording programmatically.
They also show an example app that demonstrates different types of capture including video recording, ref: https://github.com/mrousavy/react-native-vision-camera/blob/28fc6a68a5744efc85b532a338e2ab1bc8fa45fe/example/src/views/CaptureButton.tsx
...
const onStoppedRecording = useCallback(() => {
isRecording.current = false;
cancelAnimation(recordingProgress);
console.log('stopped recording video!');
}, [recordingProgress]);
const stopRecording = useCallback(async () => {
try {
if (camera.current == null) throw new Error('Camera ref is null!');
console.log('calling stopRecording()...');
await camera.current.stopRecording();
console.log('called stopRecording()!');
} catch (e) {
console.error('failed to stop recording!', e);
}
}, [camera]);
const startRecording = useCallback(() => {
try {
if (camera.current == null) throw new Error('Camera ref is null!');
console.log('calling startRecording()...');
camera.current.startRecording({
flash: flash,
onRecordingError: (error) => {
console.error('Recording failed!', error);
onStoppedRecording();
},
onRecordingFinished: (video) => {
console.log(`Recording successfully finished! ${video.path}`);
onMediaCaptured(video, 'video');
onStoppedRecording();
},
});
// TODO: wait until startRecording returns to actually find out if the recording has successfully started
console.log('called startRecording()!');
isRecording.current = true;
} catch (e) {
console.error('failed to start recording!', e, 'camera');
}
}, [camera, flash, onMediaCaptured, onStoppedRecording]);
//#endregion
...
Here is some of my code:
<TouchableOpacity
style={styles.button}
onPress={this.onPress}
>
<Text> Play Sound </Text>
</TouchableOpacity>
I want to write a function "onPress" which will play an .mp3 sound.
I have already imported react-native-sound and have my .mp3 file ready to go, I just don't know how to play the sound once the onPress function is called.
In my opinion, if you want to listen the sound, you can try this.
Syntax = react.
Import Sound from "react-native-sound";
Sound.setCategory('Playback');
const whoosh = new Sound('whoosh.mp3', Sound.MAIN_BUNDLE, (error) => {
if (error) {
console.log('failed to load the sound', error);
return;
};
whoosh.play((success) => {
if (success) {
console.log('successfully finished playing');
} else {
console.log('playback failed due to audio decoding errors');
reset the player to its uninitialized state (android only)
whoosh.reset();
}
The easiest way is First to create a new instance like Following.
create this in a constructor to load it when the component mount
Note: please put your mp3 or wav file in android/app/src/main/res/raw
const whoosh = new Sound('swoosh.mp3', Sound.MAIN_BUNDLE);
just call it in your function
whoosh.play()
npm install react-native-sound and link with your project.
Import sound from react-native-sound
// or
import Sound from 'react-native-sound';
Put your mp3 file inside the folder and mention the path:
const requireAudio = require('./xyz.mp3');
Place this code inside your "onPress" function.
const s = new Sound(requireAudio, (e) => {
if (e) {
console.log('Error in SOUND', e);
return;
}
s.play(() => s.release());
});
I am trying to check whether the user is connected to internet. I am using NetInfo like this (from the documentation):
componentDidMount() {
NetInfo.isConnected.addEventListener('change', this.handleConnectionChange);
NetInfo.isConnected.fetch().done(
(isConnected) => { this.setState({ status: isConnected }); }
);
}
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('change', this.handleConnectionChange);
}
handleConnectionChange = (isConnected) => {
this.setState({ status: isConnected });
console.log(`is connected: ${this.state.status}`);
}
The strange is that the first time loading the screen where I am doing this is working fine. But when I start turning on/of my wifi the results are different: sometimes it detects the change sometime no. Someone having the same issue?
In my experience, the iOS simulator doesn't 'notice' when the internet connection is re-connected when using the React Native NetInfo class.
It is rather annoying. However, for me it works as intended on a real device.