我需要从 phone microphone 获取音频流并在 linux 中播放

I need to get audio stream from phone microphone and play it in linux

我尝试使用 react-native-recording 和 react-native-microphone-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格式。

我已经在服务器中发送了一个 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!');
            })
        }
    });
})

可以在 Linux 机器

中使用此命令播放创建的 out.pcm 文件

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