# Recipe 84: Convert a file of text numbers into a sound

def textToSound(filename):

  # Set up the sound
  sound = makeEmptySound(3)
  soundIndex = 1

  # Set up the file
  file = open(filename,"rt")
  contents=file.readlines()
  file.close()
  fileIndex = 0

  # Keep going until run out sound space or run out of file contents
  while (soundIndex < getLength(sound)) and (fileIndex < len(contents)):
    sample=float(contents[fileIndex])  # Get the file line
    setSampleValueAt(sound,soundIndex,sample)
    fileIndex = fileIndex + 1
    soundIndex = soundIndex + 1

  return sound

