Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: eaterofpies on June 20, 2007, 05:30:28 pm

Title: Text to speech modification
Post by: eaterofpies on June 20, 2007, 05:30:28 pm
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
Title: Re: Text to speech modification
Post by: Wobble73 on June 20, 2007, 05:51:48 pm
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
Title: Re: Text to speech modification
Post by: eaterofpies on June 20, 2007, 08:30:26 pm
I dont know about it actually being useful but cheers for the welcome anyway :D
Title: Re: Text to speech modification
Post by: Polpolion on June 20, 2007, 11:03:31 pm
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.
Title: Re: Text to speech modification
Post by: Goober5000 on June 21, 2007, 12:39:52 am
Hm.  This would be useful to put in some sort of mod.tbl.
Title: Re: Text to speech modification
Post by: asyikarea51 on June 21, 2007, 01:01:49 am
I could use this too. It'll save loads of headaches on tech room readouts! :nod:

I've never scripted in my life either (http://209.85.12.236/5024/118/emo/bangwall.gif)
Title: Re: Text to speech modification
Post by: Turey on June 21, 2007, 03:16:36 am
Hm.  This would be useful to put in some sort of mod.tbl.

I like it too.
Title: Re: Text to speech modification
Post by: Wobble73 on June 21, 2007, 03:28:24 am



You must not be looking very hard.

Oh really!, examples please!  :P
Title: Re: Text to speech modification
Post by: eaterofpies on June 21, 2007, 06:38:35 am
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/speech.cpp)

http://dedibox.geezas.com/~pies/fs2_open/speechlist.tbl (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
Title: Re: Text to speech modification
Post by: karajorma on June 21, 2007, 08:54:16 am
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.
Title: Re: Text to speech modification
Post by: eaterofpies on June 21, 2007, 09:10:15 am
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.
Title: Re: Text to speech modification
Post by: WMCoolmon on June 22, 2007, 03:01:50 am
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.
Title: Re: Text to speech modification
Post by: eaterofpies on June 22, 2007, 03:47:05 am
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
Title: Re: Text to speech modification
Post by: WMCoolmon on June 22, 2007, 10:15:53 am
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.
Title: Re: Text to speech modification
Post by: eaterofpies on June 22, 2007, 02:45:18 pm
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 (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.
Title: Re: Text to speech modification
Post by: taylor on June 24, 2007, 12:40:33 am
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.
Title: Re: Text to speech modification
Post by: eaterofpies on June 24, 2007, 06:00:40 am
Cool.

Thanks for the info, suggestions and help.
Title: Re: Text to speech modification
Post by: eaterofpies on June 25, 2007, 08:16:20 pm
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
Title: Re: Text to speech modification
Post by: Kaine on June 25, 2007, 09:59:54 pm
A useful addition to the FS2SCP inside 10 posts? the force is strong with this one.
Title: Re: Text to speech modification
Post by: Fabian on July 01, 2007, 02:40:16 am
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
Title: Re: Text to speech modification
Post by: karajorma on July 01, 2007, 03:39:14 am
I had a very similar conversation with Goober about practically the same question earlier this week. The problem I found is varying descriptions of the strncpy function.

However, I found this on the MSDN page (http://msdn2.microsoft.com/en-us/library/xdsywd25(VS.80).aspx).

Quote
Security Note
strncpy does not check for sufficient space in strDest; it is therefore a potential cause of buffer overruns. Keep in mind that count limits the number of characters copied; it is not a limit on the size of strDest. See the example below.


Sometimes I *really* miss IndexOutOfBoundsException. Which is ironic considering the number of times I've cursed at it.
Title: Re: Text to speech modification
Post by: eaterofpies on July 02, 2007, 08:32:47 pm
I only remembered it because we did some stuff on stack smashing at uni and our lecturer basically said always use memcpy.

IIRC the current code ive uploaded uses memcpy then forces the last byte to \0 so that 1 it wont overflow and 2 the last byte will always be \0 (otherwise it would be uninitialised.

Cheers for the info and letting me know im doing it roughly right :)

Steve
Title: Re: Text to speech modification
Post by: colecampbell666 on July 03, 2007, 07:22:49 am
Doesn't BtRl (the demo) have a voicepack, or are you talking exclusively about the techroom. It would be good if someone could implement the standard techroom speech for capella/fs1 era mods with many of the same ships, and if people actuallyincluded tech descriptions in their mods. How come people don't already do this?
Title: Re: Text to speech modification
Post by: eaterofpies on July 03, 2007, 04:41:20 pm
the BtRL demo does have a voicepack for most of the stuff but the tech room and player released missions dont.

Im not entirely sure what you mean in the second part.

All this modification does is search the text sent to the text to speech for a word (eg viper) and replaces the text with something that the computer will pronounce correctly(eg. vi'per) the replacelemts are listed in the sounds.tbl file so in theory any mod could do this.
Title: Re: Text to speech modification
Post by: Trivial Psychic on July 05, 2007, 03:50:20 pm
I think he means voice acted techroom descriptions.  The game never shipped with any, and in fact there is no support ATM for matching techroom descriptions with pre-recorded audio files.  What I'd like to see, is the ability to specify different sim-speech voices for different messages.  For example, if we can get say 7 different sim-speech voices, a campaign designer could vary them around in-mission so you don't always have the same voice for every character.  Granted, getting your hands on more than the basic 3 voices isn't exactly easy... not that coding this wouldn't be hard either.
Title: Re: Text to speech modification
Post by: colecampbell666 on July 08, 2007, 04:08:50 pm
Sry about that post, I wa thinking that Fs had techroom voice. It would still be a nice feature.