Author Topic: The gift of simulated speech  (Read 3265 times)

0 Members and 1 Guest are viewing this topic.

Offline RandomTiger

  • Senior Member
  • 211
The gift of simulated speech
The following code was easy to program. The difficult stuff was getting it working in the briefings, ingame, techroom etc.

I had originally intended to keep this exclusive to my exe (a non fs2_open project) but since I developed it with help from the community (mainly Karajorma) I feel I have to make it public source now.

I need a coder to contact me for the rest of the code to make it work in freespace. Do not attempt to put it in yourself, that was the tricky bit, much better to have a nice easy copy and paste session. Its your to use or not as you wish.

Anyone wanting to use this for a non freespace project I would prefer to be consulted but at the very least I want credit for my code.

I hope someone is willing to put this in, its not a difficult job and you dont need to know anything about sound or anything.

My e-mail address is in my profile, use it.

- RT

fsspeech.h
Code: [Select]

/*
 * Code created by Thomas Whittaker (RT) for a Freespace 2 source code project
 *
 * You may not sell or otherwise commercially exploit the source or things you
 * created based on the source.
 *
*/

#ifndef _FSSPEECH_H_
#define _FSSPEECH_H_

enum
{
FSSPEECH_FROM_TECHROOM,
FSSPEECH_FROM_BRIEFING,
FSSPEECH_FROM_INGAME,
FSSPEECH_FROM_MAX
};

bool fsspeech_init();
void fsspeech_deinit();
void fsspeech_play(int type, char *text);
void fsspeech_stop();
void fsspeech_pause(bool playing);

void fsspeech_start_buffer();
void fsspeech_stuff_buffer(char *text);
void fsspeech_play_buffer(int type);

#endif


fsspeech.cpp
Code: [Select]

/*
 * Code created by Thomas Whittaker (RT) for a Freespace 2 source code project
 *
 * You may not sell or otherwise commercially exploit the source or things you
 * created based on the source.
 *
*/

#include "speech.h"
#include "osregistry.h"

#include "fsspeech.h"

const int MAX_SPEECH_BUFFER_LEN = 4096;

bool FSSpeech_play_from[FSSPEECH_FROM_MAX];
char *FSSpeech_play_id[FSSPEECH_FROM_MAX] =
{
"SpeechTechroom",
"SpeechBriefings",
"SpeechIngame"
};

char Speech_buffer[MAX_SPEECH_BUFFER_LEN] = "";
int  Speech_buffer_len;

bool fsspeech_init()
{
if(speech_init() == false) {
return false;
}

// Get the settings from the registry
for(int i = 0; i < FSSPEECH_FROM_MAX; i++) {
FSSpeech_play_from[i] =
os_config_read_uint(NULL, FSSpeech_play_id[i], 0) ? true : false;
}

return true;
}

void fsspeech_deinit()
{
speech_deinit();
}

void fsspeech_play(int type, char *text)
{
if(type >= FSSPEECH_FROM_MAX) return;
if(FSSpeech_play_from[type] == false) return;

speech_play(text);
}

void fsspeech_stop()
{
speech_stop();
}

void fsspeech_pause(bool playing)
{
if(playing) {
speech_pause();
} else {
speech_resume();
}
}

void fsspeech_start_buffer()
{
Speech_buffer_len = 0;
Speech_buffer[0] = '\0';
}

void fsspeech_stuff_buffer(char *text)
{
int len = strlen(text);

if(Speech_buffer_len + len < MAX_SPEECH_BUFFER_LEN) {
strcat(Speech_buffer, text);
}

Speech_buffer_len += len;
}

void fsspeech_play_buffer(int type)
{
fsspeech_play(type, Speech_buffer);
}


speech.h
Code: [Select]

/*
 * Code created by Thomas Whittaker (RT) for a Freespace 2 source code project
 *
 * You may not sell or otherwise commercially exploit the source or things you
 * created based on the source.
 *
*/

#ifndef _SPEECH_H_
#define _SPEECH_H_

const int MAX_SPEECH_CHAR_LEN = 10000;

bool speech_init();
void speech_deinit();
bool speech_play(char *text);
bool speech_play(unsigned short *text);
bool speech_pause();
bool speech_resume();
bool speech_stop();

#endif


speech.cpp
Code: [Select]

/*
 * Code created by Thomas Whittaker (RT) for a Freespace 2 source code project
 *
 * You may not sell or otherwise commercially exploit the source or things you
 * created based on the source.
 *
*/

#include "stdafx.h"

#include
#include

#include "speech.h"

ISpVoice *Voice_device;
bool Speech_init = false;

unsigned short Conversion_buffer[MAX_SPEECH_CHAR_LEN];

bool speech_init()
{
  ::CoInitialize(NULL);
    Speech_init = SUCCEEDED(CoCreateInstance(
CLSID_SpVoice,
NULL,
CLSCTX_ALL,
IID_ISpVoice,
(void **)&Voice_device));

return Speech_init;
}

void speech_deinit()
{
if(Speech_init == false) return;

Voice_device->Release();
    ::CoUninitialize();
}

bool speech_play(char *text)
{
if(Speech_init == false) return true;
if(text == NULL) return false;

int len = strlen(text);

if(len > (MAX_SPEECH_CHAR_LEN - 1)) {
len = MAX_SPEECH_CHAR_LEN - 1;
}

for(int i = 0; i < len; i++) {
Conversion_buffer[i] = (unsigned short) text[i];
}

Conversion_buffer[i] = '\0';

return speech_play(Conversion_buffer);
}

bool speech_play(unsigned short *text)
{
if(Speech_init == false) return true;
if(text == NULL) return false;

speech_stop();
  return SUCCEEDED(Voice_device->Speak(text, SPF_ASYNC, NULL));
}

bool speech_pause()
{
if(Speech_init == false) return true;
return SUCCEEDED(Voice_device->Pause());
}

bool speech_resume()
{
if(Speech_init == false) return true;
return SUCCEEDED(Voice_device->Resume());
}

bool speech_stop()
{
if(Speech_init == false) return true;
    return SUCCEEDED(Voice_device->Speak( NULL, SPF_PURGEBEFORESPEAK, NULL ));
}

 

Offline RandomTiger

  • Senior Member
  • 211
The gift of simulated speech
Or someone could checkout a bug free build for me and I could work it into that, give it back and you guys could cvs it back in.

 

Offline Inquisitor

The gift of simulated speech
There is no such thing as a bug free build :)
No signature.

 

Offline RandomTiger

  • Senior Member
  • 211
The gift of simulated speech
Well, give me a shout when you have something stable enough and someone's willing to be my cvs buddy.

Seems a bit of a sad day when a feature with so much potential use, already fully coded and ready to be intergrated is not jumped apon.

To be honest I'm getting a bit worried about the source code project. This is an interesting thread.

http://www.hard-light.net/forums/index.php/topic,15868.0.html

Ed, could you get back to me on my bugzilla e-mails please.

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
The gift of simulated speech
I would do something but I'm in the middle of a bit of a mess with some things, BWO is getting some much needed work done, I'm trying to get my decal code to work again, and I'm getting a new computer in the next few days, and my dad is removeing 'his property' from the house wich will include this computer (though I am the one who paid it off :rolleyes: ) in short order.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Inquisitor

The gift of simulated speech
I created bugzilla stuff for you Tom. What am I missing? Lemme check that I created categories for you, I might have forgot that.

I fail to see why that particular post should cause you to worry about the entire project? These guys have busted their bums, I think there is alot of stuff that wasn't there a year ago, and that works pretty well.

As for this feature, we'll get to it you posted it on:  06-26-2003 05:10 PM

and it's now the 29th.
No signature.

 

Offline Fry_Day

  • 28
The gift of simulated speech
I'll take it. My current build is the latest CVS with working (yet slow) decals and minor fixes required for glowmaps. I'm E-mailing away.

 

Offline Inquisitor

The gift of simulated speech
Fry: were you interested in joining the team?
No signature.

 

Offline RandomTiger

  • Senior Member
  • 211
The gift of simulated speech
Quote
Originally posted by Inquisitor
I created bugzilla stuff for you Tom. What am I missing? Lemme check that I created categories for you, I might have forgot that.


Would it be possible to give me that level of control over that section of the bug system?

Quote


I fail to see why that particular post should cause you to worry about the entire project? These guys have busted their bums, I think there is alot of stuff that wasn't there a year ago, and that works pretty well.


It just seems to have gotten very quiet around here.

 

Offline RandomTiger

  • Senior Member
  • 211
The gift of simulated speech
Is the launcher in cvs?
Has it been modified since I submitted it?
It will need updating / replacing for the speech stuff.

 

Offline HotSnoJ

  • Knossos Online!
  • 29
    • http://josherickson.org
The gift of simulated speech
So what exactly does this code do?
I have big plans, now if only I could see them through.

LiberCapacitas duo quiasemper
------------------------------
Nav buoy - They mark things

 

Offline RandomTiger

  • Senior Member
  • 211
The gift of simulated speech
A text to speech system that will read messages / briefing that there is no voice acting for using simulated speech.

Dont worry, it will be optional.

http://www.hard-light.net/forums/index.php/topic,15603.0.html

  

Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
The gift of simulated speech
better than missing changes in your orders. just dont give up on mp3 voiceovers yet.
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN

 

Offline Inquisitor

The gift of simulated speech
No, the launcher is not in CVS, we have a zipped copy of your old code.

As for Bugzilla, lemme look, I think I will have to make you an overall administrator to let you add and delete things at whim.

Does you CVS account still work? CVS is great for things like getting small changes to and from... That way you don;t keep having to ask people to make you a zip file...
No signature.