Page 1 of 1

The freeware translation script Text to R2D2

Posted: Sat Nov 19, 2011 5:42 am
by patforkin
Hallo!
Is it possible to acquire or test the code of the "text to R2D2 translation script"?
I am interested in knowing how it works.
Regards, patforkin.

Re: The freeware translation script Text to R2D2

Posted: Mon Nov 21, 2011 6:02 pm
by roger
While I don't want to reveal the entire source code, I can at least post the code for the routine that analyzes the text and generates beeps for each character.

The application has 94 different sounds that are stored in an array called beeps(). Individual sounds in this array can be accessed by specifying an index, e.g. beeps(index) where "index" is in the range 0..93. The following code translates a string (named "Text") into an array of ASCII codes. The routine then loops through the array and determines which sound to play by subtracting 33 from each ASCII code and then playing the sound with the resulting index.

Code: Select all

  // Split Text into an array of characters
  dim chars() as string = split(Text,"")
  // Convert array of characters to an array of ASCII codes
  dim asciis() as integer
  for each char as string in chars
    asciis.Append asc(char)
  next
  
  // Play the corresponding sound for each ASCII code
  for i as integer = 0 to UBound(asciis)
    dim ascii as integer = asciis(i)
    dim s as sound
    // Determine which sound to play
    if ascii < 33 or ascii > 126 then
      s = silence
    else
      s = beeps(ascii-33)
    end 
    // Play the sound
    s.Play
    // wait until the sound is done playing
    do
    loop until not s.IsPlaying
  next