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.
The freeware translation script Text to R2D2
-
- Posts: 2
- Joined: Fri Nov 18, 2011 2:36 am
- roger
- Site Admin
- Posts: 467
- Joined: Fri Apr 24, 2009 12:41 am
- Contact:
Re: The freeware translation script Text to R2D2
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.
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