my code runs forever, unless i restart session /u/qhelspil Python Education

when i restart session, my code runs hte amoun tof time i specified, its like that for couple of times, until it keeps runnin forever without stopping.

this is the source of my code, i jusst made little changes ( adding path)

this snippet sometimes runs 3 seconds, sometimes forever

RECORD = “”” const sleep = time => new Promise(resolve => setTimeout(resolve, time)) const b2text = blob => new Promise(resolve => { const reader = new FileReader() reader.onloadend = e => resolve(e.srcElement.result) reader.readAsDataURL(blob) }) var record = time => new Promise(async resolve => { stream = await navigator.mediaDevices.getUserMedia({ audio: true }) recorder = new MediaRecorder(stream) chunks = [] recorder.ondataavailable = e => chunks.push(e.data) recorder.start() await sleep(time) recorder.onstop = async ()=>{ blob = new Blob(chunks) text = await b2text(blob) resolve(text) } recorder.stop() }) “”” def record_audio(sec,path): display(Javascript(RECORD)) s = output.eval_js(‘record(%d)’ % (sec*1000)) b = b64decode(s.split(‘,’)[1]) audio = AudioSegment.from_file(BytesIO(b)) audio.export(path, format=’wav’) return audio record_audio(3,’output1.wav’)

this snippet runs forever, idk why

import threading thread1 = threading.Thread(target=record_audio, args=([3,’output2.wav’])) thread2 = threading.Thread(target=record_audio, args=([3,’output3.wav’])) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”)

why is that?

submitted by /u/qhelspil
[link] [comments]

​r/learnpython when i restart session, my code runs hte amoun tof time i specified, its like that for couple of times, until it keeps runnin forever without stopping. this is the source of my code, i jusst made little changes ( adding path) this snippet sometimes runs 3 seconds, sometimes forever RECORD = “”” const sleep = time => new Promise(resolve => setTimeout(resolve, time)) const b2text = blob => new Promise(resolve => { const reader = new FileReader() reader.onloadend = e => resolve(e.srcElement.result) reader.readAsDataURL(blob) }) var record = time => new Promise(async resolve => { stream = await navigator.mediaDevices.getUserMedia({ audio: true }) recorder = new MediaRecorder(stream) chunks = [] recorder.ondataavailable = e => chunks.push(e.data) recorder.start() await sleep(time) recorder.onstop = async ()=>{ blob = new Blob(chunks) text = await b2text(blob) resolve(text) } recorder.stop() }) “”” def record_audio(sec,path): display(Javascript(RECORD)) s = output.eval_js(‘record(%d)’ % (sec*1000)) b = b64decode(s.split(‘,’)[1]) audio = AudioSegment.from_file(BytesIO(b)) audio.export(path, format=’wav’) return audio record_audio(3,’output1.wav’) this snippet runs forever, idk why import threading thread1 = threading.Thread(target=record_audio, args=([3,’output2.wav’])) thread2 = threading.Thread(target=record_audio, args=([3,’output3.wav’])) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”) why is that? submitted by /u/qhelspil [link] [comments] 

when i restart session, my code runs hte amoun tof time i specified, its like that for couple of times, until it keeps runnin forever without stopping.

this is the source of my code, i jusst made little changes ( adding path)

this snippet sometimes runs 3 seconds, sometimes forever

RECORD = “”” const sleep = time => new Promise(resolve => setTimeout(resolve, time)) const b2text = blob => new Promise(resolve => { const reader = new FileReader() reader.onloadend = e => resolve(e.srcElement.result) reader.readAsDataURL(blob) }) var record = time => new Promise(async resolve => { stream = await navigator.mediaDevices.getUserMedia({ audio: true }) recorder = new MediaRecorder(stream) chunks = [] recorder.ondataavailable = e => chunks.push(e.data) recorder.start() await sleep(time) recorder.onstop = async ()=>{ blob = new Blob(chunks) text = await b2text(blob) resolve(text) } recorder.stop() }) “”” def record_audio(sec,path): display(Javascript(RECORD)) s = output.eval_js(‘record(%d)’ % (sec*1000)) b = b64decode(s.split(‘,’)[1]) audio = AudioSegment.from_file(BytesIO(b)) audio.export(path, format=’wav’) return audio record_audio(3,’output1.wav’)

this snippet runs forever, idk why

import threading thread1 = threading.Thread(target=record_audio, args=([3,’output2.wav’])) thread2 = threading.Thread(target=record_audio, args=([3,’output3.wav’])) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”)

why is that?

submitted by /u/qhelspil
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *