@@ -446,13 +446,6 @@ int IsMusicVoxAvailable () {
446446
447447extern ScriptAudioChannel scrAudioChannel[MAX_GAME_CHANNELS];
448448
449- ScriptAudioChannel *PlayVoiceClip (CharacterInfo *ch, int sndid, bool as_speech)
450- {
451- if (!play_voice_nonblocking (ch ? ch->index_id : -1 /* narrator */ , sndid, as_speech))
452- return NULL ;
453- return &scrAudioChannel[SCHAN_SPEECH];
454- }
455-
456449// Construct an asset name for the voice-over clip for the given character and cue id
457450static String get_cue_filename (int charid, int sndid, bool old_style)
458451{
@@ -477,15 +470,11 @@ static String get_cue_filename(int charid, int sndid, bool old_style)
477470 return Path::ConcatPaths (get_voice_assetpath (), asset_filename);
478471}
479472
480- // Play voice-over clip on the common channel;
481- // voice_name should be bare clip name without extension
482- static bool play_voice_clip_on_channel (const String &voice_name)
473+ static AssetPath find_voice_clip (const String &voice_name)
483474{
484- stop_and_destroy_channel (SCHAN_SPEECH);
485-
486475 // TODO: perhaps a better algorithm, allow any extension / sound format?
487476 // e.g. make a hashmap matching a voice name to a asset name
488- std::array<const char *, 3 > exts = {{ " mp3" , " ogg" , " wav" }};
477+ std::array<const char *, 3 > exts = { { " mp3" , " ogg" , " wav" } };
489478 AssetPath apath = get_voice_over_assetpath (voice_name);
490479 bool found = false ;
491480 for (auto *ext : exts)
@@ -498,9 +487,22 @@ static bool play_voice_clip_on_channel(const String &voice_name)
498487
499488 if (!found) {
500489 debug_script_warn (" Speech file not found: '%s'" , voice_name.GetCStr ());
501- return false ;
490+ return AssetPath () ;
502491 }
503492
493+ return apath;
494+ }
495+
496+ // Play voice-over clip on the common channel;
497+ // voice_name should be bare clip name without extension
498+ static bool play_voice_clip_on_channel (const String &voice_name)
499+ {
500+ stop_and_destroy_channel (SCHAN_SPEECH);
501+
502+ AssetPath apath = find_voice_clip (voice_name);
503+ if (!apath)
504+ return false ;
505+
504506 std::unique_ptr<SoundClip> voice_clip (load_sound_clip (apath, " " , false ));
505507 if (voice_clip != nullptr ) {
506508 voice_clip->fileName = apath.Name ;
@@ -590,16 +592,34 @@ bool play_voice_speech(int charid, int sndid)
590592bool play_voice_nonblocking (int charid, int sndid, bool as_speech)
591593{
592594 // don't play voice if we're skipping a cutscene
593- if (!play.ShouldPlayVoiceSpeech ())
595+ if (!play.ShouldPlayVoiceSpeechNonBlocking ())
594596 return false ;
595597 // don't play voice if there's a blocking speech with voice-over already
596- if (play.IsBlockingVoiceSpeech ())
598+ if (as_speech && play.IsBlockingVoiceSpeech ())
597599 return false ;
598600
599601 String voice_file = get_cue_filename (charid, sndid, !game.options [OPT_VOICECLIPNAMERULE]);
600602 return play_voice_clip_impl (voice_file, as_speech, false );
601603}
602604
605+ const ScriptAudioChannel *play_voice_clip_as_type (int charid, int sndid, int type, int chan, int priority, int repeat)
606+ {
607+ // don't play voice if we're skipping a cutscene
608+ if (!play.ShouldPlayVoiceSpeechNonBlocking ())
609+ return nullptr ;
610+
611+ String voice_file = get_cue_filename (charid, sndid, !game.options [OPT_VOICECLIPNAMERULE]);
612+ AssetPath apath = find_voice_clip (voice_file);
613+ if (!apath)
614+ return nullptr ;
615+
616+ ScriptAudioClip sc_clip; // pass temp dummy clip
617+ sc_clip.fileName = apath.Name ;
618+ sc_clip.fileType = ScriptAudioClip::GetAudioFileTypeFromExt (Path::GetFileExtension (apath.Name ).GetCStr ());
619+ sc_clip.bundlingType = kAudioBundle_SpeechVox ;
620+ return play_audio_clip (AudioPlayback (&sc_clip, type), chan, priority, repeat, 0 , false );
621+ }
622+
603623void stop_voice_speech ()
604624{
605625 if (!play.speech_has_voice )
0 commit comments