Мне нужно получить аудиопоток с микрофона телефона и воспроизвести его в Linux - PullRequest
0 голосов
/ 30 ноября 2018

Я пытался использовать пакеты response-native-recording и response-native-микрофон-stream, но оба они возвращали 16-битные целые числа.

    componentDidMount() {
            Recording.init({
                    bufferSize: 4096,
                    sampleRate: 44100,
                    bitsPerChannel: 16,
                    channelsPerFrame: 1,
            })

            const socket = openSocket('http://192.168.1.147:3000');
            const listener = Recording.addRecordingEventListener(data => {
                    if (this.webView) {
                            this.webView.postMessage(data)
                            socket.emit("audio", data);
                            console.log(data);
                    }
            })

            Recording.start()
    }

как я могу воспроизвести эти возвращенные числа как аудиов моем рабочем столе Linux.Я знаю, что здесь используется формат PCM.

1 Ответ

0 голосов
/ 07 декабря 2018

Я отправил 16-битный массив на сервер и сохранил его в файл

var io = require('socket.io')();
const fs = require('fs');
var spawn = require('child_process').spawn;

const port = 3000;
io.listen(port);
console.log("listening port 3000 ...");

io.on('connection', (client) => {
    console.log('any value');
    client.on('createConnection', () => {
            client.emit('connectionResponse', 'New Client with ID: ' + client.id);
        });
    client.on('connection', (data) => {
        console.log("client connected");
    })
    client.on('audio', (data) => {
        // phone audio data parameters
        //Recording.init({
        //bufferSize: 256,
        //sampleRate: 8000,
        //bitsPerChannel: 16,
        //channelsPerFrame: 1,
        // play created out.pcm file with this command in linux machine
        // aplay -r 8000 -t raw -f S16_LE out.pcm
        console.log("data recivied");

        for(let i=0 ; i < data.length; i++ ){
            var buf = new Buffer(2);
            buf.writeInt16LE(data[i],0);
            console.log(buf);
            fs.appendFile('out.pcm',buf, (err) => {
                if (err) throw err;
                //console.log('xThe lyrics were updated!');
            })
        }
    });
})

С помощью этой команды можно воспроизвести созданный файл out.pcm на компьютере с Linux

aplay -r 8000 -t raw -f S16_LE out.pcm

...