using the below code in processing

edited April 2016 in Python Mode

i am having issue with the import os . i am new with processing and python both please help me with this.

import os   //error
def soundToImageAndText1():
       sound=pickAFile()
       outstr = textPrint1(sound)
       pic = imagePrint1(sound)
       txtFile = open('txtFile.txt','w')
       txtFile.write(outstr)
       txtFile.close()
       writePict(pic,"/Desktop/picture.jpg")

def soundToImageAndText2():
      sound=pickAFile()
      outstr = textPrint2(sound)
      pic = imagePrint2(sound)
      txtFile = open('txtFile.txt','w')
      txtFile.write(outstr)
      txtFile.close()
      writePict(pic,"/Desktop/picture.jpg")

def textPrint1(sound):
      f = open(sound, "rb")
      count = 0;
      data = f.read();
      outstr = ""
      while data:
        if((data == ' ') or (data >= 'a' and data <= 'z') or (data >= 'A' and data <= 'Z')):
          outstr += data
          count += 1
          data = f.read(1)
      print count
      return outstr



def imagePrint1(sound):
      size = os.path.getsize(sound)
      print size
      f = open(sound, "rb")
      xy = int(sqrt(size))
      print xy
      pic = makeEmptyPicture(xy, xy)
      picpixels = getPixels(pic)
      newsize = xy * xy
      count = 0
      data = f.read(1)
      while data and count < newsize:
        setColor(picpixels[count], makeColor(ord(data)))
        count += 1
        data = f.read(1)
      explore(pic)
      return pic



def writePict(pict,name):
      file=getMediaPath(name)
      writePictureTo(pict,file)

Answers

Sign In or Register to comment.