another update to the soundlib interface
sound_verbal(char *text, int32_t gender, int32_t tone, int32_t vol,
int32_t moreinfo);
-- NetHack will call this function when it wants to pass text of
spoken language by a character or creature within the game.
-- text is a transcript of what has been spoken.
-- gender indicates MALE or FEMALE sounding voice.
-- tone indicates the tone of the voice.
-- vol is the volume (1% - 100%) for the sound.
-- moreinfo is used to provide additional information to the soundlib.
-- there may be some accessibility uses for this function.
It may be useful for accessibility purposes too.
A preliminary implementation has been attempted for macsound to test
the interface on macOS. No tinkering of the voices has been done.
Use of the test implementation requires the following at build time with make.
WANT_SPEECH=1
That needs to be included on the make command line to enable the test code,
otherwise just the interface update is compiled in.
I don't know for certain when AVSpeechSynthesizer went into macOS, but older versions
likely don't support it, and would just leave off the WANT_SPEECH=1.
If built with WANT_SPEECH=1, the 'voices' NetHack option needs to be enabled.
It was a bit strange, when I first started up the test, to hear Asidonhopo,
the shopkeeper, talking to me as I entered his shop and interacted with him.
This commit is contained in:
@@ -11,6 +11,12 @@
|
||||
/* #import <Foundation/Foundation.h> */
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
#define SPEECH_SOUNDS
|
||||
#ifdef SPEECH_SOUNDS
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Sample sound interface for NetHack
|
||||
*
|
||||
@@ -27,9 +33,11 @@ static void macsound_soundeffect(char *, int32_t, int32_t);
|
||||
static void macsound_hero_playnotes(int32_t, const char *, int32_t);
|
||||
static void macsound_play_usersound(char *, int32_t, int32_t);
|
||||
static void macsound_ambience(int32_t, int32_t, int32_t);
|
||||
|
||||
static void macsound_verbal(char *, int32_t, int32_t, int32_t, int32_t);
|
||||
static int affiliate(int32_t seid, const char *soundname);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Sound capabilities that can be enabled:
|
||||
* SOUND_TRIGGER_USERSOUNDS | SOUND_TRIGGER_HEROMUSIC
|
||||
@@ -40,7 +48,10 @@ static int affiliate(int32_t seid, const char *soundname);
|
||||
struct sound_procs macsound_procs = {
|
||||
SOUNDID(macsound),
|
||||
SOUND_TRIGGER_HEROMUSIC | SOUND_TRIGGER_SOUNDEFFECTS
|
||||
| SOUND_TRIGGER_ACHIEVEMENTS,
|
||||
| SOUND_TRIGGER_ACHIEVEMENTS
|
||||
#ifdef SND_SPEECH
|
||||
| SOUND_TRIGGER_VERBAL,
|
||||
#endif
|
||||
macsound_init_nhsound,
|
||||
macsound_exit_nhsound,
|
||||
macsound_achievement,
|
||||
@@ -48,6 +59,7 @@ struct sound_procs macsound_procs = {
|
||||
macsound_hero_playnotes,
|
||||
macsound_play_usersound,
|
||||
macsound_ambience,
|
||||
macsound_verbal,
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -312,6 +324,36 @@ macsound_play_usersound(char *filename UNUSED, int volume UNUSED, int idx UNUSED
|
||||
|
||||
}
|
||||
|
||||
#ifdef SND_SPEECH
|
||||
#define SPEECHONLY
|
||||
#else
|
||||
#define SPEECHONLY UNUSED
|
||||
#endif
|
||||
|
||||
static void
|
||||
macsound_verbal(char *text SPEECHONLY, int32_t gndr SPEECHONLY, int32_t tone_of_voice UNUSED, int32_t vol UNUSED, int32_t moreinfo UNUSED)
|
||||
{
|
||||
#ifdef SND_SPEECH
|
||||
NSMutableString *speechstring;
|
||||
AVSpeechUtterance *text2speechutt;
|
||||
AVSpeechSynthesizer *synthesizer;
|
||||
|
||||
synthesizer = [[AVSpeechSynthesizer alloc]init];
|
||||
speechstring = [NSMutableString stringWithUTF8String:text];
|
||||
text2speechutt = [AVSpeechUtterance speechUtteranceWithString:speechstring];
|
||||
text2speechutt.rate = 0.50f;
|
||||
text2speechutt.pitchMultiplier = 0.8f;
|
||||
text2speechutt.postUtteranceDelay = 0.2f;
|
||||
text2speechutt.volume = (float) vol / 100;
|
||||
if (gndr > 0)
|
||||
text2speechutt.voice = [AVSpeechSynthesisVoice voiceWithIdentifier:@"com.apple.ttsbundle.siri_female_en-GB_compact"];
|
||||
else
|
||||
text2speechutt.voice = [AVSpeechSynthesisVoice voiceWithIdentifier:@"com.apple.ttsbundle.siri_male_en-GB_compact"];
|
||||
|
||||
[synthesizer speakUtterance:text2speechutt];
|
||||
#endif /* SND_SPEECH */
|
||||
}
|
||||
|
||||
static int
|
||||
affiliate(int32_t id, const char *soundname)
|
||||
{
|
||||
|
||||
@@ -25,6 +25,9 @@ static void windsound_hero_playnotes(int32_t instrument, const char *str, int32_
|
||||
static void windsound_play_usersound(char *, int32_t, int32_t);
|
||||
static void windsound_ambience(int32_t ambienceid, int32_t ambience_action,
|
||||
int32_t hero_proximity);
|
||||
static void windsound_verbal(char *text, int32_t gender, int32_t tone,
|
||||
int32_t vol, int32_t moreinfo);
|
||||
|
||||
|
||||
/* supporting routines */
|
||||
static void adjust_soundargs_for_compiler(int32_t *, DWORD *, char **);
|
||||
@@ -34,7 +37,7 @@ struct sound_procs windsound_procs = {
|
||||
SOUNDID(windsound),
|
||||
SOUND_TRIGGER_USERSOUNDS | SOUND_TRIGGER_SOUNDEFFECTS
|
||||
| SOUND_TRIGGER_HEROMUSIC | SOUND_TRIGGER_AMBIENCE
|
||||
| SOUND_TRIGGER_ACHIEVEMENTS,
|
||||
| SOUND_TRIGGER_ACHIEVEMENTS | SOUND_TRIGGER_VERBAL,
|
||||
windsound_init_nhsound,
|
||||
windsound_exit_nhsound,
|
||||
windsound_achievement,
|
||||
@@ -42,6 +45,7 @@ struct sound_procs windsound_procs = {
|
||||
windsound_hero_playnotes,
|
||||
windsound_play_usersound,
|
||||
windsound_ambience,
|
||||
windsound_verbal,
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -110,7 +114,13 @@ windsound_achievement(schar ach1, schar ach2, int32_t repeat)
|
||||
|
||||
static void
|
||||
windsound_ambience(int32_t ambienceid, int32_t ambience_action,
|
||||
int32_t hero_proximity)
|
||||
int32_t hero_proximity)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
windsound_verbal(char *text, int32_t gender, int32_t tone,
|
||||
int32_t vol, int32_t moreinfo)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user