Skip to content

如何实现实时语音输入?/ How to Implement Real-Time Voice Input #601

Answered by wang0618
ChemInCode asked this question in Q&A
Discussion options

You must be logged in to vote

You need to write some js to achieve this, here is an example:

import base64

from pywebio.output import *
from pywebio.session import eval_js
from pywebio_battery import put_audio

# https://developer.mozilla.org/en-US/docs/Web/API/MediaStream_Recording_API/Using_the_MediaStream_Recording_API
voice_recording_js = """
new Promise((resolve, reject) => {
    recording_duration_seconds = 3;
    if (!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)){
        resolve(null)
        console.error("getUserMedia not supported");
        return;            
    }
    
    navigator.mediaDevices
        .getUserMedia(
            {
                audio: true,
            },
        )

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ChemInCode
Comment options

Answer selected by ChemInCode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants