Author Topic: Text to speech modification  (Read 5649 times)

0 Members and 3 Guests are viewing this topic.

Text to speech modification
I was playing BtRL and got fed up with the text to speech really struggling with some of the words(like viper, adama, mk) and remembered that UT2004 has a list of conversions in a config file which corrects things like that.

I dont know any c or c++ but have done a fair amount of java and while it would probably be a 5 min job for anyone else I thought I should probably have a go at implementing this myself as you no doubt have more important things to be working on.

The current implementation uses a compiled in array of strings as I couldnt find a good way to load it from a file.

The code belongs in the speech.cpp file in the speech_play function just after the length of the input text is checked against the maximum length.

Code: [Select]
//start nasty code

//do the conversion
//nead to load this from a file really
const NUMWORDS=8;
char *wordOriginal[NUMWORDS] = {"adama","mk", "ii", "vii", "ix","dradis","viper","tyllium"};
char *wordReplace[NUMWORDS] = {"aadamma","mark", "2", "7", "9","draydiss","vi'per","t'illi-um"};

char textCopy[MAX_SPEECH_CHAR_LEN];

//work on a copy of the text as it might not be safe to modify the original
memcpy(textCopy,text,len + 1);

//force to lower case to make matching easier (might be a bad idea)
strlwr(textCopy);


for (int j = 0; j < NUMWORDS; j++){
replace_all(textCopy,wordOriginal[j],wordReplace[j],MAX_SPEECH_CHAR_LEN,len);
}

//shouldnt be bigger than max as replace_all uses the limit
len = strlen(textCopy);

//end nasty code

This was tested using the 3.6.9 code from the CVS repository with BtRL (not FS2 etc).
I checked the latest version and couldnt see anything like it.

If anyone could finish it off so that it loads from a file that would be great.

I fully expect that there are major problems with the way ive implemented it but at least i didnt just say "dude dude dude dude dude dude implement this dude dude dude dude is it done yet. dude?" :D

Steve
« Last Edit: June 20, 2007, 05:46:04 pm by eaterofpies »

 

Offline Wobble73

  • 210
  • Reality is for people with no imagination
    • Steam
Re: Text to speech modification
Wow, a newbie comes along with something useful! A rarity, I've not seen this since hip63 arrived with his DVD!

Anyway eaterofpies.............

:welcome:

I'm sure someone will find this useful and no doubt pick it up and run with it! (Not me however, never scripted in my life, wouldn't know how).  :D
Who is General Failure and why is he reading my hard disk?
Early bird gets the worm, but the second mouse gets the cheese
Ambition is a poor excuse for not having enough sense to be lazy.
 
Member of the Scooby Doo Fanclub. And we're not talking a cartoon dog here people!!

 You would be well adviced to question the wisdom of older forumites, we all have our preferences and perversions

 
Re: Text to speech modification
I dont know about it actually being useful but cheers for the welcome anyway :D

 

Offline Polpolion

  • The sizzle, it thinks!
  • 211
Re: Text to speech modification
Wow, a newbie comes along with something useful! A rarity, I've not seen this since hip63 arrived with his DVD!

Anyway eaterofpies.............

:welcome:

I'm sure someone will find this useful and no doubt pick it up and run with it! (Not me however, never scripted in my life, wouldn't know how).  :D

You must not be looking very hard.

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: Text to speech modification
Hm.  This would be useful to put in some sort of mod.tbl.

 

Offline asyikarea51

  • 210
  • -__-||
Re: Text to speech modification
I could use this too. It'll save loads of headaches on tech room readouts! :nod:

I've never scripted in my life either

 

Offline Turey

  • Installer dude
  • 211
  • The diminutive form of Turambar.
    • FreeSpace Open Installer Homepage
Re: Text to speech modification
Hm.  This would be useful to put in some sort of mod.tbl.

I like it too.
Creator of the FreeSpace Open Installer.
"Calm. The ****. Down." -Taristin
why would an SCP error be considered as news? :wtf: *smacks Cobra*It's a feature.

 

Offline Wobble73

  • 210
  • Reality is for people with no imagination
    • Steam
Re: Text to speech modification



You must not be looking very hard.

Oh really!, examples please!  :P
Who is General Failure and why is he reading my hard disk?
Early bird gets the worm, but the second mouse gets the cheese
Ambition is a poor excuse for not having enough sense to be lazy.
 
Member of the Scooby Doo Fanclub. And we're not talking a cartoon dog here people!!

 You would be well adviced to question the wisdom of older forumites, we all have our preferences and perversions

 
Re: Text to speech modification
After goober mentioned the mod.tbl thing and as there seemed to be some interest in this I modified the code to load it from speechlist.tbl (copied and modified code from elsewhere)

The current code only works for windows because all the ifdefs were confusing me :(

http://dedibox.geezas.com/~pies/fs2_open/speech.cpp

http://dedibox.geezas.com/~pies/fs2_open/speechlist.tbl

oh I didnt update the log as I didnt know if that was automated or not.

Steve

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Text to speech modification
The log is automatically updated by CVS so you shouldn't update that.

Speech currently only works on Windows so as long as you've not added anything that will get compiled in on other platforms you should be safe.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

  
Re: Text to speech modification
I meant that the code I added only effects the text under windows (its in the #ifdef _WIN32 bit). Ill have another look when ive got a min to see if i can work out the ifdefs and make it work with everything.

EDIT: oops misread your post

It will modify it for all platforms now but it *should* work if and when more platforms have text ot speech.
I replaced the file so just use the link in my previous post.
« Last Edit: June 21, 2007, 09:42:06 am by eaterofpies »

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Text to speech modification
It should be put in sounds.tbl as a separate section. It's not worth adding yet another .tbl, and it's already part of the 'sounds' subsystem, so it doesn't make as much sense to add it to mod.tbl (which is mostly brought up as a place for more miscellaneous items).

Changing the format to "$Word: +Replacement:" would also help with readability and makes more sense to me, but whatever. I'm happy to see somebody taking this up because it'll help resolve a number of gripes people have had.
-C

 
Re: Text to speech modification
Ill change it to the $Word: +Replacement: format.
I didnt know what the conventions are for this sort of thing as i only found fs2 open recently and I have never modded the game contents so thanks for suggesting it.

The reason I use a seperate file is for ease of modification by a user. How a word is pronounced can really annoy people as shown by me writing this  as it took 2 days to get it to build under windows (or perhapse i just have too much time :-/). The opinions on pronounciation can also vary from person to person especially with alien words.

If you still think i should change it to go in souds.tbl / mods.tbl then I will (its not exactly a big change)

edit:
changed to the $Word: +Replacement: format
modified it so that each word has to have a marker infront of it to make sure that replacing "ii" doesnt effect "vii" instead you match " ii" (note the preceeding space)
same urls as before
« Last Edit: June 22, 2007, 07:48:45 am by eaterofpies »

 

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Re: Text to speech modification
The reason I use a seperate file is for ease of modification by a user. How a word is pronounced can really annoy people as shown by me writing this  as it took 2 days to get it to build under windows (or perhapse i just have too much time :-/). The opinions on pronounciation can also vary from person to person especially with alien words.

The problem is, if everybody used a different table it would kind of negate that effect. Either way, they have to open a text file and add '#Speech Replacement' or '#Words' and the words they want.
-C

 
Re: Text to speech modification
uploaded the speech.cpp file again now it reads the word list from sounds.tbl but doesnt require it. if there isnt a word list it just doesnt replace any words.

Add something along the lines of the following to the sounds.tbl to get it to do its stuff.

Code: [Select]
;Word replacement list for the text to speech
;All white space characters and the first character of each word and replacement will be ignored.
;This allows a preceeding white space character to be recognised so that a search for " ii" does not match " vii"
;All text to speech data is forced to lower case before matching
#Word List Start
$Word: ' adama
+Replacement: ' aadamma

$Word: ' mk
+Replacement: ' mark

$Word: ' ii
+Replacement: ' 2

$Word: ' vii
+Replacement: ' 7

$Word: ' ix
+Replacement: ' 9

$Word: ' dradis
+Replacement: ' draydiss

$Word: ' viper
+Replacement: ' vi'per

$Word: ' tyllium
+Replacement: ' t'illi-um
#Word List End

To save you the scroll heres a fresh link to the speech file.
http://dedibox.geezas.com/~pies/fs2_open/speech.cpp


edit:
I noticed today that I get a hacked tables warning if I have this modification in the sounds file.

Is there a reason sounds.tbl is checked for multiplayer? I cant think of anyway to get an advantage from modifying it but I dont really have any form of understanding of almost all of the code.
« Last Edit: June 23, 2007, 07:33:03 pm by eaterofpies »

 

Offline taylor

  • Super SCP/Linux Guru
  • Moderator
  • 212
    • http://www.icculus.org/~taylor
Re: Text to speech modification
Is there a reason sounds.tbl is checked for multiplayer?
No, there is no reason that most of the tables should ever be checked for multi either, but the old code doesn't consider any one tbl different from another.  The new FS2NetD code for 3.6.10 is smart enough to know that though, and will only bother checking tables (both tbl and tbm) that could affect gameplay.

 
Re: Text to speech modification
Cool.

Thanks for the info, suggestions and help.

 
Re: Text to speech modification
I noticed a problem in the text to speech code and im not sure what the best way to fix it is.

currently the code does this
--------
get text length

if length > max length then length = max length

memcpy(copy of text, original text,length)
---------
the problem with this is that if the length is > max length the terminating null will be stripped off (along with some other stuff but the important bit is the null) meaning its not a valid string.

strcpy will have a similar problem as it doesnt do bounds checking and could overflow the destination.

Is the best way of fixing this just forcing the last character of the copy of the text to a null to make it a valid string? Ive had a look around but wanted to know what people prefered.

Sorry for the basic C question.

edit: uploaded a new copy which forces the last byte to null
« Last Edit: June 26, 2007, 08:52:29 am by eaterofpies »

 

Offline Kaine

  • 27
Re: Text to speech modification
A useful addition to the FS2SCP inside 10 posts? the force is strong with this one.

 

Offline Fabian

  • AI Code Modulator
    Temporal Mechanic
  • 25
Re: Text to speech modification
strcpy will have a similar problem as it doesnt do bounds checking and could overflow the destination.

Is the best way of fixing this just forcing the last character of the copy of the text to a null to make it a valid string? Ive had a look around but wanted to know what people prefered.

There is strncpy, which does bounds checking, but you still need to force the last byte to '\0' in case of overflow.

To be safe for example doing just:

char dest[257];

strncpy(dest, src, 256)
dest[256]='\0';

always works, because that additional '\0' does never hurt, but is useful _if_ it overflows ...

Also be aware of the off-by-one error that easily happens if buf is too small, as buf[256] means space is assigned from buf[0] to buf[255].

cu

Fabian