-
Notifications
You must be signed in to change notification settings - Fork 64
Description
I am using the Recording module to stream data to PC over websocket as below. But the data is getting sent only once. If I press start for the second time , keypress in sent to PC but no voice data sent as the eventlistener not getting called. What am i doing wrong here?
import React from 'react';
import {Component,Text,View,Button, Alert } from 'react-native';
import Recording from 'react-native-recording';export default class VoiceScreen extends React.Component {
constructor(){
super();
this.state={
status:true
}
}
componentDidMount(){
//await this.checkPermission();
Recording.init({bufferSize: 640, sampleRate: 16000, bitsPerChannel: 16, channelsPerFrame: 1, }) Recording.addRecordingEventListener(this.DataHandler); ws.onmessage=(m)=> { console.log(m.data +"status "+this.state.status); if(m.data=='READY') { this.startVoice(); } else { this.stopVoice(); } }
}
startVoice(){
Recording.start();
}stopVoice()
{
Recording.stop();
}DataHandler=(data)=>{
console.log(" Sending auido data of len "+data.length*2); var pcm_len = data.length*2; //data.unshift(pcm_len>>8); data.unshift(pcm_len); data.unshift(0x03); var view = new Uint16Array(data); //var view1 = new Uint8Array(view); ws.send(view); data.pop(); data.pop();
}
sendVoiceKeyPress(){
cmd = []; cmd.push(0x04); cmd.push(0x00); cmd.push(0x05); cmd.push(0x00); cmd.push(0x56); cmd.push(0x4F); cmd.push(0x49); cmd.push(0x43); cmd.push(0x45); start_speech = new Uint8Array(cmd); ws.send(start_speech); this.setState({status:false});
}
sendVoiceKeyRelease(){
this.stopVoice();
cmd = [];
cmd.push(0x05);
cmd.push(0x00);
cmd.push(0x05)
cmd.push(0x00);
cmd.push(0x56);
cmd.push(0x4F);
cmd.push(0x49);
cmd.push(0x43);
cmd.push(0x45);
stop_speech = new Uint8Array(cmd);
ws.send(stop_speech);
this.setState({status:true});}
componentWillUnmount() {
//Recording.stop()
}
render() {
return( <View> {this.state.status?<Button title='start' onPress={()=>this.sendVoiceKeyPress()}/>:<Button title='stop' onPress={()=>this.sendVoiceKeyRelease()}/>} </View> )
}
}
`