[python-win32] Simple audio recording
mc@mclaveau
mc at mclaveau.com
Tue Mar 18 20:36:27 CET 2014
Re!
Thanks for your return.
France ; Ardèche
Le 18.03.14 13:32, Jacob Kruger a écrit :
> OK, quick test, and, thanks!
> Just got it to start recording, while, using sound_lib loaded a prior
> recording into a FileStream, and let it play back while the new
> recording was taking place, then called finrecord(), loaded new
> recording clip into another stream, and you could hear the whole thing
> operating/cooperating, etc. etc.
> In other words, perfect!
> <smile>
>
> Jacob Kruger
> Blind Biker
> Skype: BlindZA
> "Roger Wilco wants to welcome you...to the space janitor's closet..."
>
> ----- Original Message -----
> *From:* mc at mclaveau <mailto:mc at mclaveau>
> *To:* python-win32 at python.org <mailto:python-win32 at python.org>
> *Sent:* Tuesday, 18 March, 2014 7:55 AM
> *Subject:* Re: [python-win32] Simple audio recording
>
> Hi!
>
> The exampl below run OK on my Win.7 with Python 2.7 + pywin32.
>
> @+
> --
>
> ------------------------------------------------------------------------
> # -*- coding: utf-8 -*-
>
> import time,os
> from ctypes import windll, c_buffer
>
> class mci:
>
> def __init__(self):
> self.w32mci = windll.winmm.mciSendStringA
> self.w32mcierror = windll.winmm.mciGetErrorStringA
>
> def send(self,commande):
> buffer = c_buffer(255)
> errorcode = self.w32mci(str(commande),buffer,254,0)
>
> if errorcode: # There was an error
> return errorcode, self.get_error(errorcode)
> else: # commande returned 0
> return errorcode,buffer.value
>
> def get_error(self,error):
> """Given an error code, will return a description of the
> error."""
> error = int(error)
> buffer = c_buffer(255)
> self.w32mcierror(error,buffer,254)
> return buffer.value
>
> def directsend(self, txt):
> (err,buf)=self.send(txt)
> if err != 0:
> print'Erreur',str(err),'sur',txt,':',buf
> return (err,buf)
>
> def record(self):
> print"Record"
> self.directsend('open new type waveaudio alias toto')
> self.directsend('Set toto time format milliseconds')
> self.directsend('set toto bitspersample 8') # 8 bits ou
> 16 bits
> self.directsend('set toto samplespersec 11025') # 11025
> low quality 22050 medium quality 44100 high quality (CD)
> self.directsend('set toto channels 1') # 1 mono 2 stereo
>
> self.directsend('record toto')
> time.sleep(0.1)
>
> def finrecord(self, nomfichier):
> self.directsend('stop toto')
> self.directsend('save toto '+nomfichier)
> self.directsend('close toto')
> #self.directsend('delete toto')
>
> def play(self, nomfichier):
> self.directsend('open "'+nomfichier+'" alias toto')
> self.directsend('set toto time format milliseconds')
> err,duree=self.directsend('status toto length ')
> self.directsend('play toto from 0 to '+str(duree))
> time.sleep(float(duree)/1000.0)
> self.directsend('stop toto')
> self.directsend('close toto')
>
> if __name__=='__main__':
> message=mci()
> message.record()
> for i in xrange(4):
> time.sleep(1)
> print 4-i
> print "Fin"
> message.finrecord(os.getcwd()+"\\test.wav")
> ------------------------------------------------------------------------
>
>
>
> Le 18.03.14 06:14, Jacob Kruger a écrit :
>> Am playing around with a bit of a personal assistant app, that
>> includes letting people record smallish audio notes/sound clips,
>> etc., and am currently using pyAudio to handle recording -
>> relatively simple/easy, etc., but, one small issue seems to be
>> that if I use something like winsound to beep just before start
>> recording, to sort of notify user that recording is about to
>> start, this seems to possibly cause input/output stream issues.
>> In other words, possible to avoid/work around, but, just
>> wondering what guys would recommend looking into for simple
>> little bits of audio recording of sound clips, etc.?
>> TIA
>>
>> Jacob Kruger
>> Blind Biker
>> Skype: BlindZA
>> "Roger Wilco wants to welcome you...to the space janitor's closet..."
>>
>>
>> _______________________________________________
>> python-win32 mailing list
>> python-win32 at python.org
>> https://mail.python.org/mailman/listinfo/python-win32
>
> ------------------------------------------------------------------------
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
>
>
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> https://mail.python.org/mailman/listinfo/python-win32
--
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20140318/1b0e9440/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 41683 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-win32/attachments/20140318/1b0e9440/attachment-0001.jpe>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.gif
Type: image/gif
Size: 50388 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-win32/attachments/20140318/1b0e9440/attachment-0001.gif>
More information about the python-win32
mailing list