[英]Real-time audio streaming from javascrit to python-django
i want to record client's microphone in the browser with javascript and send it in real-time to process the audio stream in python.我想用javascript在浏览器中记录客户端的麦克风并实时发送它以在python中处理音频流。 Is django able to do this in real-time?
django 是否能够实时执行此操作?
Thank you!谢谢!
Yes you can do that using the javascript that allow you to microphone and give blob data in form of *.wav,*.webm
etc format then you need to send response on django side using ajax i give a link to allow you record audio or video etc是的,您可以使用允许您使用麦克风并以
*.wav,*.webm
等格式提供blob 数据的javascript做到这一点,然后您需要使用 ajax 在 django 端发送响应我提供一个链接以允许您录制音频或视频等
First you see mention link then another it example
首先你会看到提及链接,然后是另一个它的例子
if you use p5 js that be posiable and如果你使用 p5 js 是 posiable 和
let mic, fft;
let recorder, soundFile;
let can1
function setup() {
can1=createCanvas(400, 400);
noFill();
can1.parent('canvas-area');
mic = new p5.AudioIn();
mic.start();
fft = new p5.FFT();
fft.setInput(mic);
}
function draw() {
background(255,255,255);
let spectrum = fft.analyze();
beginShape();
for (i = 0; i < spectrum.length; i++) {
ellipse(200,200,100+spectrum[i],100+spectrum[i]);
}
endShape();
}
function mediaplay(){
getAudioContext().resume();
recorder = new p5.SoundRecorder();
recorder.setInput(mic);
soundFile = new p5.SoundFile();
recorder.record(soundFile);
}
function mediastop(){
recorder.stop();
AjaxRequest()
// saveSound(soundFile,'test.wav')
}
//do logic for send 1 half minute chunks or minute chucks
function AjaxRequest() {
var form = new FormData();
form.append("wavfile", soundFile.getBlob(), "file");
$.ajax({
url: "You url",
method: "POST",
data: form, //here passing the wav file
dataType: "json",
processData: false,
contentType:false,
success:function(data){
console.log(data.success)
},
});
}
@django view.py @django view.py
import FileSystemStoragefrom django.http
import JsonResponse,HttpResponsefrom django.views.decorators.csrf
import csrf_exemptimport osos.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
from django.core.files.storage import default_storageclass GetFile(View):
def get(self,request):
return JsonResponse(status=200,data={},safe=False)
# @csrf_exempt
def post(self,request):
wavfile=request.FILES['wavfile']
#logic of your wav file what you want to do
return JsonResponse(status=200,data={'success':'success'},safe=False)
Here i give link我在这里给链接
If you satisfaction of my answer let me know如果您对我的回答满意,请告诉我
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.