The goal is to make a simple walkie-talkie in React Native through Wifi Direct.
I was able to capture a microphone stream on the first phone (192.168.49.1) and send it to the second phone (192.168.49.200) by using the library react-native-udp.
How do I play the transferred audio on the other phone?
Tried different audio apps, but they don't support raw audio buffer AFAIK?
Should I first save it to a file and then stream this local file?
Any ideas?
import React, {Component} from 'react';
import {ScrollView, StyleSheet, Text, View} from 'react-native';
import Recording from "react-native-recording";
import dgram from 'react-native-udp';
class App extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
Recording.init({
bufferSize: 4096,
sampleRate: 44100,
bitsPerChannel: 16,
channelsPerFrame: 1,
});
Recording.start();
let a = dgram.createSocket('udp4');
let aPort = 23456;
a.bind(aPort, '192.168.49.1', function(err) {
if (err) throw err;
});
a.once('listening', function() {
const listener = Recording.addRecordingEventListener((data) => {
a.send(msg, undefined, undefined, aPort, '192.168.49.200', function(err) {
if (err) throw err;
});
}
}
}
render() {
return (
<View style={styles.container}>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
}
}
export default App;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…