小编Ali*_*ron的帖子

如何使用从浏览器发送到 Nodejs 服务器的 Blob 进行 Google Speech-to-Text

我正在尝试设置服务器以使用 接收来自客户端浏览器的音频SocketIO,然后通过 Google Speech-to-Text 对其进行处理,最后将文本回复给客户端。

最初和理想情况下,我想设置得有点像此页面上的工具:https : //cloud.google.com/speech-to-text/

我尝试使用getUserMedia和流式传输它SocketIO-Stream,但我不知道如何“管道” MediaStream

相反,现在我决定MediaRecorder在客户端使用,然后将数据作为 blob 一起发送(见本示例)。

然后我申请toString('base64')blob 并在 blob 上调用 google-cloud/speech client.recognize()

客户端(我正在使用 VueJS):

        new Vue({
            el: '#app',
            data: function () {
                return ({
                    msgs: [],
                    socket: null,
                    recorder: null,
                    : []
                })
            },
            mounted: function () {
                this.socket = io.connect('localhost:3000/user');
                console.log('Connected!')
                this.socket.on('text', function (text) {
                    this.msgs.push(text)
                })
            },
            methods: {
                startRecording: function () {
                    if (this.recorder && …
Run Code Online (Sandbox Code Playgroud)

audio-streaming node.js socket.io getusermedia google-speech-api

9
推荐指数
1
解决办法
2420
查看次数