[python-win32] Simple audio recording

Jacob Kruger jacob at blindza.co.za
Wed Mar 19 00:41:52 CET 2014


Works if am running code from/via interpreter, but, once I compile it to executable using cx, no longer beeps...<smile>

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
"Roger Wilco wants to welcome you...to the space janitor's closet..."

  ----- Original Message ----- 
  From: Vernon D. Cole 
  To: mc at mclaveau 
  Cc: python-win32 
  Sent: Tuesday, 18 March, 2014 11:53 PM
  Subject: Re: [python-win32] Simple audio recording


  Just for fun (I know it works in console mode)...

  What happens if you try a "beep" the old fashioned way?

  print chr(7)





  On Mon, Mar 17, 2014 at 11:55 PM, mc at mclaveau <mc at mclaveau.com> wrote:

    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/20140319/7331a9a4/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: C:\art\wtst\signature.gif
Type: image/gif
Size: 50388 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-win32/attachments/20140319/7331a9a4/attachment-0001.gif>


More information about the python-win32 mailing list