Skip to content
/a/ FaceCue Performance Studio

FMOD

Playing a line on the face when the voice plays through FMOD.

A game that plays its voice through FMOD keeps that audio out of Unity, so there is no Audio Source for the character to follow. The FaceCue FMOD Bridge takes its place. It becomes the character's Voice Source, and the character speaks each line for as long as its voice sounds, holds where it is through a pause, and stops when the voice ends.

What Works

Speak(key)
Speak(event, key)
Follow(event, key)
Follow(event, keys)
Follow(event) StartMicrophone
FollowMicrophone
Follow(channel)
Plays the audio Yes No No No
Baked Phoneme ✓ ✓ ✓ ✗§
Live Viseme ✓† ✓† ✓†‡ ✓†‡
Live Amplitude ✓ ✓ ✓‡ ✓‡

† Where Meta's lip sync library runs. See What Runs Where.

‡ FaceCue follows the voice as it plays, so the mouth moves with each sound rather than just ahead of it. See Without a Key and Live Voices.

§ A live voice has no bake, so a character set to Baked Phoneme follows it in Live Viseme or Live Amplitude instead.

Events

The bridge has a call for each way a game plays a voice line through an FMOD event.

  • Speak(key) plays a line of an audio table itself, through the bridge's Dialogue Event, or through an event you pass with Speak(event, key).
  • Follow(event, key) follows an audio table line your game played through a dialogue event of its own, the way FMOD's Programmer Sounds example does. Follow(event, keys) does the same for an event that plays several of them, such as a conversation on one timeline.
  • Follow(event) follows an event your game played that holds its voice line itself.

An event can play more than the voice, such as a click before it, music under it or other characters, and the character still follows its own voice. Follow sets out how, for each way of calling it.

Live Voices

The bridge follows a live voice as well as a line: the player's own microphone, and other players' voices in voice chat. Live voices have calls of their own, in the table's last column. A live voice has no bake, so the character follows it in Live Viseme or Live Amplitude, whatever the project's Unreadable Clips is set to. It is heard as it is made, so the mouth moves with each sound rather than just ahead of it (see The Mouth Leads the Sound).

A live voice takes the place of a line: starting one ends a line playing through the bridge, and a line spoken or followed through the bridge ends it. The character follows it until Stop, or until the voice itself stops.

Which call follows a live voice depends on where it comes from.

The voice What to use
The player's own, with nothing else recording it StartMicrophone, or the FMOD Microphone
The player's own, recorded through FMOD by your game or its voice chat FollowMicrophone, in place of the FMOD Microphone
Another player's, played on an FMOD channel of its own, the way ODIN's FMOD integration plays each remote player Follow(channel)
Another player's, played through an FMOD event, by a programmer sound for instance Follow, as for any event
Another player's, handed to your game as audio rather than played through FMOD A Voice Source of your own

Timelines

A line on FMOD's own Timeline track is spoken too, with no call at all. See From a Timeline.

What Does Not

  • Audio files that share a name are not supported. A line's cues are found by its audio file's name, so of two recordings with one name, in different banks, under different keys or in different languages, only one can have cues of its own. Give each recording a name of its own before baking.
  • Moving a playing event's timeline ends the line for the character, while the sound plays on. Call Follow again after the seek, and the character picks the voice up where it now is.

Setting Up

  1. Install FMOD for Unity. FaceCue's FMOD integration turns on by itself when the editor next starts, or at once with Tools â–¸ FaceCue â–¸ Integrations â–¸ Refresh. Its row is FMOD for Unity in the FaceCue Hub (see Integrations).
  2. In FMOD Studio, put the voice lines in an audio table, or give each line an event of its own. Build the project (File â–¸ Build): FMOD for Unity reads the built banks, never the Studio project's audio.
  3. Bake the lines with the Cue Baker from the audio files' folder, into your Unity project, and add them to a Cue Registry. A line's cues are found by the name of its audio file, so keep the names the files have. In a localized audio table, give each language's recording a name of its own (welcome_en.wav, welcome_jp.wav), so each language finds its own cues.
  4. Add the FaceCue FMOD Bridge to the character. The OneClick Wizard offers it on its Apply step while FMOD for Unity is in the project, or add it beside the FaceCue Brain from Add Component â–¸ Firecrest â–¸ FaceCue â–¸ Integrations â–¸ FaceCue FMOD Bridge. It makes itself the character's Voice Source when the game starts.
  5. Put an FMOD Studio Listener in the scene, on the camera or the player. Without one, FMOD plays a positioned event silently.

The Cue Clip Composer previews an FMOD line straight from its audio file, and the Cue Registry marks which of its lines are in the FMOD project, in Unity, or both.

The Bridge's Settings

The FaceCue FMOD Bridge has three Basic settings, and its defaults suit most projects. Its Advanced settings, Followed Voice and Voice Prefix, decide which sound is the voice in an event followed without a key, and are set out under Without a Key.

The FaceCue FMOD Bridge inspector: the tier toggles, a note on what the bridge does, then Character set to the character's FaceCue Brain, Dialogue Event set to an FMOD event, Cue Name on From Audio File, the Advanced row Followed Voice on All Baked Files, and the Expert row Voice Memory on Auto

The bridge on a character. Dialogue Event is only needed for Speak(key), and Cue Name is best left on From Audio File.
  • Character is the character the bridge voices. Left empty, it is the FaceCue Brain on the bridge's object, or the nearest one above it.
  • Dialogue Event is the event Speak(key) plays a line through: an event with a programmer instrument, which plays whichever line of an audio table it is given. Only Speak(key) needs it. A game that follows its own events, or passes an event to Speak(event, key), can leave it empty.
  • Cue Name decides which name a line's cues are found by, below.

A line's cues come from the character's Cue Registry, found by that name, and load as the character's On First Load setting says (see When a Line's Cues Load).

Which Name Finds the Cues

  • From Audio File, the default: the name of the audio file the line's voice plays, which is the name cues baked from that file carry. This is what you want unless your project names its cues another way, and it is the one to keep wherever a key differs from its file's name, as it does in a localized audio table.
  • From Key: the key your game passes.
  • Custom: a name your own code gives, through FaceCueFmodBridge.CustomCueName, or a class that extends the bridge and overrides ResolveCueName.

A line followed with Follow(event) has no key, so it is always named after its audio file, whichever of these is set.

A Custom rule is assigned once, before the first line plays, and every bridge set to Custom asks it. Here, a project whose cues were baked under each line's key with vo_ in front:

using Firecrest.Systems.FaceCue.Integrations.Fmod;
using UnityEngine;

public static class VoiceCueNames
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    static void Register()
    {
        FaceCueFmodBridge.CustomCueName = (bridge, key) => "vo_" + key;
    }
}

Returning nothing names that line as From Audio File would.

Unity's Built-In Audio

FaceCue works the same whether Unity's own audio is on or off, so set it as your project needs. Where you can, follow FMOD's setup and turn it off, with Disable Unity Audio under Audio in Project Settings.

Try the Examples

FaceCue comes with two examples. Use them as a start for your own code, or to test your project's setup before going further.

Try Your Lines

The Simple FMOD Line Player example plays your FMOD lines on a character from its inspector, with no code. Add Simple FMOD Line Player (Example) to a character that has the bridge, from Add Component â–¸ FaceCue â–¸ Integrations, then press Play.

  • Line Key takes a line of an audio table. The button beside it lists the FMOD project's lines, and picking one fills in its key. Speak Line plays it.
  • Line Event takes an event that plays one line. Play And Follow starts it on the character, as a game would, and has the bridge follow it.
  • Stop Line stops whichever is playing, and Preload Line loads the cues of the line in Line Key ahead of time.

Under them, the Line section shows the line as the character has it: whether it is playing and how far in, the name its cues were found by, whether the live modes can follow it, whether the bridge is the character's Voice Source, and which speech mode the mouth is using.

The Simple FMOD Line Player inspector while a line plays: Bridge, Line Key with its picker button and Speak Line, Line Event and Play And Follow, then the Line section reading Playing, the time, the cue name, Live Modes Available, Voice Source This Bridge and Speech Mode Used Baked Phoneme, with Stop Line and Preload Line

A line of an audio table playing on the character, with the Line section showing how the character has it.

Each button calls one public method of the component, so its script, Examples/FMOD/SimpleFmodLinePlayer.cs, shows the code each one runs.

Try the Microphone

The FMOD Microphone example records a microphone through FMOD and has the character follow it. Add FMOD Microphone (Example) to a character that has the bridge, from Add Component â–¸ FaceCue â–¸ Integrations, then press Play. It records whether Unity's built-in audio is on or off, so it is the microphone to use in a game that turns Unity's audio off.

  • Bridge is the bridge it records for. Left empty, it is the bridge on the component's object, or the nearest one above it.
  • Device is the microphone to record. It lists the microphones connected now, with (System Default) first, which follows whichever input the system has as its default. A microphone picked here is remembered, and while it is not connected it stays in the list, with (Not Connected) after its name.
  • Show System Audio lists the computer's own sound outputs in Device beside its microphones, where FMOD offers them, so the character can follow whatever the computer plays, such as a call in another app.
  • Start On Enable starts the microphone when the component is enabled, and stops it when the component is disabled.

Under them, the Microphone section shows what the microphone is doing while the game runs: its state, the microphone in use, and the problem that stopped it, if one did. While the microphone is disconnected, its state reads Waiting for the Microphone.

The FMOD Microphone inspector while it records: Bridge, Device set to a microphone, Show System Audio and Start On Enable, then the Microphone section reading State Recording and the microphone In Use, with Start Microphone, Pause, Resume and Stop Microphone

A microphone recording for the character, with the Microphone section showing what it is doing.

Start Microphone, Pause, Resume and Stop Microphone each call one public method of the component, so its script, Examples/FMOD/FmodMicrophone.cs, shows the code each one runs. For push-to-talk, call its PauseMicrophone while the key is up and ResumeMicrophone while it is held. On Android, it asks the player for the microphone permission the first time it starts, and starts once the player allows it.

How the bridge treats a microphone, from choosing one to one that is disconnected, is set out from Start a Microphone on.

From a Timeline

FMOD for Unity's own Timeline track, the FMOD Event Track, plays a line on the face with nothing to call. Bind the track to the character, or to an object on it such as its head, and have a Director Watcher watch the Timeline's director, or give the character an Auto Watcher. Each clip's event is followed the way Follow(event) follows one: the bridge's Followed Voice finds the voice, and its audio file's name finds the cues. An FMOD project with an event for each line needs nothing more.

What the Character Does

The character keeps to the sound, and FMOD's track decides where the sound is. The track starts a clip's event as the playhead reaches the clip, and from then on the event plays at its own pace.

  • Pausing the director stops the event, and resuming starts it again. An event laid out on FMOD's timeline picks up where the playhead is, and the character with it. An action event starts its sound again from the beginning, and so does the character.
  • Moving the playhead inside a clip, or playing the Timeline at another speed, does not move the sound, so the character carries on with it.
  • A clip whose Stop Mode is None lets its event play on past the clip's end, and the character speaks until the voice ends.
  • Where two clips overlap, the later one has the voice. The earlier one takes it back when the later one ends, if it is still sounding.

In a recording, the line keeps to the Timeline, as any line recorded without its sound does (see Other Ways to Record). Record with Cap FPS on, in the Unity Recorder under Constant playback, as Unity recommends. FMOD plays its sound in real time, so a recording that runs faster than that reaches a line before FMOD has started it, and the character misses the start of the line or all of it.

Action Events and Clip Length

An action event, one with no timeline of its own in FMOD Studio, has no length FMOD can report, so a new clip for it takes the Timeline's default length rather than the line's. Drag the clip's end to where the line ends. The track stops the event when the clip ends, so a clip shorter than the line cuts the line short, for the character as for the sound.

From Your Code

With FMOD, as with most audio in a game, a line usually plays from your own code: the game decides when it plays, and one call on the bridge has the character speak it. A live voice, from the player's microphone or from voice chat, starts the same way. Each call below gives its declaration, what it takes, and what the character does. The calls for a line come first, then those for a microphone, then Follow a Channel, then Stop and Reading the Bridge, which work for both.

Speak a Line

public EventInstance Speak(string key)
public EventInstance Speak(EventReference dialogueEvent, string key)
Parameter What it does
stringkey
The line's key in the FMOD audio table
EventReferencedialogueEvent
The event to play the line through, in place of the bridge's Dialogue Event. It needs a programmer instrument, as the Dialogue Event does

Plays the line through the bridge's Dialogue Event, or through the event you pass, on the character, and has the character speak it. A line already playing through an earlier Speak is stopped first. Returns the event playing the line, for pausing it, stopping it or setting its parameters, or an invalid instance when the line could not start, which the Console also reports.

public FaceCueFmodBridge bridge;

public void Greet()
{
    bridge.Speak("greeting");
}

Pass an event when your game plays its lines through more than one dialogue event, such as one heard over a radio and one heard in the room. The bridge's Dialogue Event stays as it is.

public EventReference radioDialogue;

public void SayOverTheRadio(string key)
{
    bridge.Speak(radioDialogue, key);
}

Follow a Line

Has the character speak the lines an event your game started is playing. It takes the event with a line's key, with a list of keys, or alone, by how the event plays its voice, each set out below.

Call it when the event starts, or at any point while it plays. The character joins where its voice is, holds while the event is paused, and waits through anything the event plays before the voice, so nothing needs an offset. The event stays your game's: the bridge never stops, pauses or releases it, and releasing it straight after starting it, as FMOD's own examples do, is fine. FMOD keeps it until it has played, and the bridge follows it until then.

An event can play more than the voice, such as a click before it, music under it or other characters. The character follows its own voice and leaves the rest alone, by the rule of the call below. Every voice it follows is a line of its own, so a conversation, a line in a loop or a voice picked from several takes is spoken line by line. A voice that starts while another is still sounding takes over, and the earlier one is picked up again if it is still sounding when the later one ends.

With a Key

public void Follow(EventInstance instance, string key)
Parameter What it does
EventInstanceinstance
The event playing the line
stringkey
The line's key in an audio table

For an event that plays a line of an audio table, the way FMOD's Programmer Sounds example does. The voice is that key's own audio file, whatever else the event plays. If an audio table FMOD has loaded holds the key and the event never plays its file, the character does not speak, and the Console names the file the event played instead. If no loaded audio table holds the key, the Console says so, and the bridge falls back to finding the voice without a key.

dialogueInstance.start();
bridge.Follow(dialogueInstance, key);
dialogueInstance.release();

With a List of Keys

public void Follow(EventInstance instance, IReadOnlyList<string> keys)
Parameter What it does
EventInstanceinstance
The event playing the lines
IReadOnlyList<string>keys
The keys of the lines the event plays, in the order it plays them

For an event that plays several lines of an audio table, such as a conversation on one timeline. Each listed line the event plays is spoken in turn, and every other sound is left alone.

EventInstance scene = RuntimeManager.CreateInstance(conversation);
scene.start();
akari.Follow(scene, new[] { "akari_01", "akari_02" });
bob.Follow(scene, new[] { "bob_01" });
scene.release();

Prefer Putting the Keys in the Order the Event Will Play Them

The bridge makes each listed line ready while the line before it plays, so the line is ready the moment its voice starts. A line played out of order is still spoken in full, but it is made ready the moment its voice starts, which takes a little time in that frame, most on a slower device such as a phone.

In a web build every line is made ready as its voice starts, so there the order makes no difference.

Without a Key

public void Follow(EventInstance instance)
Parameter What it does
EventInstanceinstance
The event playing the line

For an event that plays a sound of its own. Each line is named after the audio file its voice plays, and its cues are found by that name. The bridge's Followed Voice setting decides which of the event's sounds is the voice:

  • All Baked Files, the default: every sound whose audio file has baked cues, another character's lines included.
  • Prefixed Files: a sound whose audio file name starts with Voice Prefix, such as akari_, whatever its letter case. With Voice Prefix left empty, the voice is found as under All Baked Files.

The bridge's settings with Followed Voice on Prefixed Files and Voice Prefix set to akari_, between Cue Name and Voice Memory

Followed Voice on Prefixed Files: this character's voice is any sound whose file name starts with akari_.
EventInstance line = RuntimeManager.CreateInstance(lineEvent);
RuntimeManager.AttachInstanceToGameObject(line, gameObject);
line.start();
bridge.Follow(line);
line.release();

Without a Key, FaceCue Follows the Line as It Plays

A line followed without a key has no copy for the bridge to read ahead in, so the bridge captures the line's audio as FMOD plays it. Live Viseme and Live Amplitude follow it, with the mouth moving with each sound rather than just ahead of it. For the mouth to lead each sound, put the line in an audio table and follow it with its key.

Under All Baked Files the line is always one with baked cues. Under Prefixed Files it can also be a line that is not baked, and then the live modes follow its sound. Either way, the project's Unreadable Clips on Skip Live Modes leaves such a line to its baked cues.

The bridge captures the audio only while something follows the line's sound, such as Live Viseme, Live Amplitude or a live Loudness Source. In a build that uses IL2CPP, other than a browser build, capturing makes a little garbage for Unity's garbage collector, about 40 KB for each second of the line. A line followed with its key makes none, and nor does a baked line played in Baked Phoneme.

Two Characters in One Event

Each character follows the same event through its own bridge, and each needs a way to tell its own lines from the other's:

  • By key: give each bridge the key, or the list of keys, of its own lines, as in the conversation above. Each line is read from its whole audio, so the mouth leads each sound.
  • By file name: without keys, set both bridges' Followed Voice to Prefixed Files, each with the start of its own lines' file names. Each line is followed as it plays, and a line that is not baked is followed too.

With All Baked Files and no keys, each character takes any line with baked cues, so each speaks the other's lines as well. The Console says so, Characters Follow the Same FMOD Event.

Preload a Line

public CuePreload Preload(string key)
Parameter What it does
stringkey
The line's key, or for an event with a sound of its own, its audio file's name

Loads a line's cues ahead of time, so the line starts with them in place. Returns a request to wait on.

Reading a Line

public class FaceCueFmodBridge : MonoBehaviour, IVoiceSource, IVoiceSamples, IVoiceOutputDelay, IVoiceSourceLogMessages
Member What it does
string read-onlyClipId
The name the line's cues are found by. Null for a live voice, which has no cues
float read-onlyLineLengthSeconds
The line's length in seconds, 0 until its voice has started. Always 0 for a live voice, which has no set end
EventInstance read-onlyEvent
The event the bridge is playing or following, valid while IsPlaying is true. Not valid for a live voice, which plays through no event

Start a Microphone

public bool StartMicrophone(FmodMicrophoneDevice device)
Parameter What it does
FmodMicrophoneDevicedevice
The microphone to record: one GetMicrophones lists, one made again from a saved choice, or FmodMicrophoneDevice.Default for the system's default input

Records the microphone through FMOD and has the character follow it. Nothing is played back, so players do not hear themselves through the bridge. To let them, record the microphone in your game, play it back your own way, and follow that recording with Follow a Microphone. Returns true when recording started, or will start once the app is back from a pause, and false when it could not, with the reason in MicrophoneProblem and in the Console.

FmodMicrophoneDevice.Default records whichever input the system has as its default, and moves to the new one when the default changes. A microphone you pick is recorded whatever the system's default is, and is found again after it is plugged into another port. List the Microphones gives the microphones to pick from, and how to keep a player's choice.

When the Microphone Is Disconnected

A picked microphone that is disconnected ends the line, and the Console says so once, FMOD Microphone Lost. The bridge then waits for that same microphone, and records it again by itself as soon as it is connected, with a new line. It never moves to another microphone by itself. To use another one, call StartMicrophone with it. On FmodMicrophoneDevice.Default, it records the system's new default input as soon as there is one.

When Your Game Records or Stops It

FMOD runs one recording of a microphone at a time, and starting a second stops the first. So the bridge never starts on a microphone your game already records. StartMicrophone leaves it alone and returns false, and the Console says so, FMOD Microphone In Use by the Game. Follow your game's recording with FollowMicrophone instead, which reads it and never starts or stops it.

The same holds the other way round. When your game starts recording a microphone the bridge is recording, the bridge's recording stops, so the character's line ends, with the same message. The bridge leaves your game's recording alone.

A recording stopped from other code, with FMOD's recordStop, ends the line too, and the bridge does not start it again by itself. To end the microphone from your own code, call Stop.

On Each Platform

  • Android. The bridge never asks for the microphone permission, so a game with a permission flow of its own keeps it. Ask with Unity's Permission.RequestUserPermission and Permission.Microphone, and call StartMicrophone once it is granted. Calling it from the answer itself is fine: the answer arrives while the app is still paused, and the bridge starts recording once the app is back, with MicrophoneState on WaitingForDevice until then. The FMOD Microphone example asks the player itself.
  • iOS. Set the app's audio session to play and record, as FMOD's own instructions for iOS say, with AVAudioSessionCategoryPlayAndRecord in UnityAppController.mm. Put FMOD's lines after Unity's own audio session lines in startUnity: with Unity's audio off, as Unity's Built-In Audio advises, Unity sets the session for playback only there. Leave Unity's Prepare iOS for Recording and Force iOS Speakers When Recording off. With them on, the first time iOS asks the player for the microphone, the game's FMOD sound can stop for the rest of the session. Fill in Microphone Usage Description in Player Settings as well. FaceCue asks for one when a macOS or iOS build starts without it.
  • A browser build has no microphone through FMOD. StartMicrophone returns false there, and the Console says so, FMOD Microphone Did Not Start.

Follow a Microphone

public bool FollowMicrophone(int driver, FMOD.Sound sound)
Parameter What it does
intdriver
The record driver your game records, the index it passed to FMOD's recordStart
FMOD.Soundsound
The sound your game records into. Its samples must be 16-bit or floating point, in one or two channels

For a game that records the microphone itself, for voice chat for example. The character follows what the recording hears, and the recording stays your game's: the bridge reads it and never starts, stops or releases it. Call it once your game has started recording. Returns true when the character follows the recording, and false when it can't be followed, with the reason in MicrophoneProblem and in the Console.

The character's line ends when your game's recording stops, when its microphone is disconnected, or when your game starts a new recording of that microphone, since the sound the bridge follows then gets no more audio. The bridge does not follow it again by itself. Call FollowMicrophone again with the recording your game makes now.

Your game's recording must loop: FMOD then writes over its oldest audio as new audio arrives, the ring buffer Reading as It Plays describes. One that does not loop stops when it is full, and the character's line ends with it. Make it at least three seconds long, as the example below does with four. That is a little more than the two seconds FaceCue keeps, since the bridge never reads the stretch FMOD is about to write over. A shorter one can lose part of the voice when a frame runs long.

FMOD.System core = RuntimeManager.CoreSystem;
core.getRecordDriverInfo(0, out _, out int rate, out _, out int channels, out _);
var info = new FMOD.CREATESOUNDEXINFO
{
    cbsize = System.Runtime.InteropServices.Marshal.SizeOf<FMOD.CREATESOUNDEXINFO>(),
    numchannels = channels,
    defaultfrequency = rate,
    format = FMOD.SOUND_FORMAT.PCM16,
    length = (uint)(rate * channels * sizeof(short) * 4),   // four seconds
};
core.createSound(IntPtr.Zero, FMOD.MODE.OPENUSER | FMOD.MODE.LOOP_NORMAL, ref info, out FMOD.Sound recording);
core.recordStart(0, recording, true);
bridge.FollowMicrophone(0, recording);

Pause and Resume a Microphone

public class FaceCueFmodBridge : MonoBehaviour, IVoiceSource, IVoiceSamples, IVoiceOutputDelay, IVoiceSourceLogMessages
Member What it does
voidPauseMicrophone()
The character stops following the microphone while it keeps recording, for push-to-talk while the player is not talking. For a microphone started by StartMicrophone or followed by FollowMicrophone
voidResumeMicrophone()
Has the character follow the microphone again

The recording stays open while the microphone is paused, so the character picks the voice up the moment it resumes.

// push-to-talk: the microphone records throughout, and the character speaks only while V is held
void Start()
{
    bridge.StartMicrophone(FmodMicrophoneDevice.Default);
    bridge.PauseMicrophone();
}

void Update()
{
    if (Input.GetKeyDown(KeyCode.V)) bridge.ResumeMicrophone();
    if (Input.GetKeyUp(KeyCode.V)) bridge.PauseMicrophone();
}

List the Microphones

public class FaceCueFmodBridge : MonoBehaviour, IVoiceSource, IVoiceSamples, IVoiceOutputDelay, IVoiceSourceLogMessages
Member What it does
void staticGetMicrophones(List<FmodMicrophoneDevice> results, bool includeSystemAudio)
Fills results with the microphones connected now, for a menu where the player picks one. With includeSystemAudio, the computer's own sound outputs follow them, where FMOD offers them. Call it while the game runs, when the list is wanted rather than every frame
void staticGetMicrophones(FMOD.System system, List<FmodMicrophoneDevice> results, bool includeSystemAudio)
The same, from an FMOD system you pass, such as FMOD for Unity's editor system for a tool that runs outside Play mode

Each is an FmodMicrophoneDevice, with its Name as the system shows it, and IsSystemDefault and IsSystemAudio to mark the system's default input and a sound output. FmodMicrophoneDevice.Default is the system's default input, whichever device that is when the microphone starts.

To keep a player's choice, save its Guid and its Name, and make it again in a later session. It is found by its GUID, and by its name when no connected device has that GUID.

// saving the player's choice
PlayerPrefs.SetString("mic.guid", device.Guid.ToString());
PlayerPrefs.SetString("mic.name", device.Name);

// making it again in a later session
var saved = new FmodMicrophoneDevice(PlayerPrefs.GetString("mic.name"), new Guid(PlayerPrefs.GetString("mic.guid")));
bridge.StartMicrophone(saved);

Reading a Microphone

public class FaceCueFmodBridge : MonoBehaviour, IVoiceSource, IVoiceSamples, IVoiceOutputDelay, IVoiceSourceLogMessages
Member What it does
MicrophoneState read-onlyMicrophoneState
What the bridge is doing with a microphone, below. Stopped while none is in use, another player's voice included
MicrophoneProblem read-onlyMicrophoneProblem
What last kept the microphone from giving the character a voice, None when nothing has. It stays after Stop, so your game can show why the microphone ended
FmodMicrophoneDevice read-onlyMicrophoneDevice
The microphone the bridge records, follows or waits for. For one started with FmodMicrophoneDevice.Default, the input that is the system's default now
public enum MicrophoneState
Value What it means
Stopped
No microphone is in use
Recording
The bridge records a microphone, and the character speaks what it hears
Following
Your game records a microphone, handed over with FollowMicrophone, and the character speaks what it hears
Paused
The microphone keeps recording, and the character holds still until ResumeMicrophone
WaitingForDevice
The bridge waits for its microphone: one that was disconnected, which it records again as soon as it is connected, or one asked for while the app was paused, which it records once the app is back

Each problem is also reported in the Console, once, with the fix. Troubleshooting has an entry for each.

public enum MicrophoneProblem
Value What it means In the Console
None Nothing has gone wrong
NotFound No connected microphone matches the one StartMicrophone was given
FMOD Microphone Not Found
Lost The microphone was disconnected while the bridge recorded it
FMOD Microphone Lost
InUseByGame Your game records the microphone through FMOD. Either it already did, so the bridge left it alone, or it started while the bridge recorded it, which ended the bridge's recording
FMOD Microphone In Use by the Game
NoPermission The app has not been given permission to use the microphone
FMOD Microphone Has No Permission
DidNotStart FMOD could not start the recording, the recording handed to FollowMicrophone could not be read, or the build is for a browser
FMOD Microphone Did Not Start
NoLongerGivingAudio The recording stopped while the character followed it. Either your game's, handed over with FollowMicrophone, stopped, was disconnected or gave way to a new recording, or the bridge's own was stopped from other code
FMOD Microphone No Longer Giving Audio

Follow a Channel

public void Follow(FMOD.Channel channel)
Parameter What it does
FMOD.Channelchannel
The channel the voice plays on. It stays your game's: the bridge never stops, pauses or releases it

Has the character follow a voice playing on an FMOD channel your game plays itself, such as another player's voice in voice chat. ODIN's FMOD integration plays each remote player on a channel of their own, which its playback component gives you. Call it once the channel has started. A line playing through the bridge ends first.

Give each remote player's character a bridge of its own, and have it follow that player's voice.

The character follows the voice in Live Viseme or Live Amplitude for as long as the channel plays, holds while it is paused, and stops when it stops. The voice is followed as it arrives, before the channel's volume and distance, so a quiet or distant player does not read as a quiet voice.

Stop

public void Stop()

Ends the line or the live voice. An event Speak started is stopped, letting its sound fade as the event is authored to. An event passed to Follow is left playing and is no longer followed. A microphone StartMicrophone started stops recording, and one the bridge waits for is no longer waited for. A recording passed to FollowMicrophone, and a channel passed to Follow, are left as they are and are no longer followed.

Reading the Bridge

public class FaceCueFmodBridge : MonoBehaviour, IVoiceSource, IVoiceSamples, IVoiceOutputDelay, IVoiceSourceLogMessages
Member What it does
FaceCueBrain read-onlyCharacter
The character the bridge voices: the FaceCue Brain in its Character field, or else the one on its object or the nearest one above it
bool read-onlyIsPlaying
True while a line's voice is sounding or paused, while a microphone records, paused or not, and while another player's channel plays
bool read-onlyIsPaused
True while a line's event is paused, while a microphone is paused with PauseMicrophone, and while another player's channel is paused
float read-onlyLinePositionSeconds
How far into the line or the live voice the character is, in seconds
bool read-onlyIsLiveVoice
True while the bridge follows a live voice: a microphone, or another player's voice on a channel. False for a line

When a Line's Cues Load

A line played through the bridge follows the character's On First Load setting, with one difference. Under Delay the Audio, a line played with Speak waits for its cues before its sound starts, since the bridge starts the sound itself. A line your game starts and the bridge follows cannot be held, so the face joins it a moment later. To start such a line with its cues in place, load them ahead of time, or call Preload.

Troubleshooting

The Character Does Not Speak the Bridge's Lines

Its Voice Source is something other than the bridge, so it follows that instead. The Console says so, FMOD Bridge Is Not the Voice Source. Assign the bridge as the character's Voice Source, or leave Voice Source empty, and the bridge takes it when the game starts.

The Character Does Not Speak a Followed Event's Line

The event played no sound the character took for its voice. The Console says why, FMOD Event Played No Voice, and names a file the event did play.

  • Followed by a key, or a list of keys: the event never played those lines. Pass the keys of the lines it plays.
  • With Followed Voice on All Baked Files: none of its sounds has baked cues the character can find. Bake the voice's audio file, and add its cues to the character's Cue Registry, or to Addressables under the address the character looks for. To follow a line that is not baked, set Followed Voice to Prefixed Files and Voice Prefix to the start of its audio file's name.
  • With Prefixed Files: no file name the event played starts with Voice Prefix. Check its spelling against the voice's file names.

The Character Misses a Line When You Record the Timeline

The recording ran faster than real time, while FMOD plays its sound in real time, so the Timeline reached the line before its voice had started. The Console says so, Recording Ran Ahead of FMOD. Record with Cap FPS on, as What the Character Does sets out.

Two Characters Speak Each Other's Lines

Both follow one event, and at least one of them finds its voice by All Baked Files, which takes any line with baked cues. The Console says so, Characters Follow the Same FMOD Event. Give each bridge the keys of its own lines, or set both to Prefixed Files, each with the start of its own lines' file names, as Two Characters in One Event sets out.

The Microphone Is Not Found

No connected microphone matches the one the bridge was given, or the system has no default input. The Console says so, FMOD Microphone Not Found, and lists the microphones that are connected. Plug the microphone in, or choose one of those:

  • With the FMOD Microphone, pick it in Device.
  • From your own code, pass one that GetMicrophones lists, or FmodMicrophoneDevice.Default for the system's default input.

With none connected, connect one, or check the system's sound input settings.

The Character Stops Following a Disconnected Microphone

The microphone the bridge recorded was disconnected, so the character's line ended. The Console says so, FMOD Microphone Lost. Connect it again, and the bridge records it again by itself. It never moves to another microphone, so to use another one, pick it in the FMOD Microphone's Device and start the microphone again, or call StartMicrophone with it. On FmodMicrophoneDevice.Default, the bridge records the system's new default input as soon as there is one.

A disconnected microphone your game recorded and handed over with FollowMicrophone is not waited for. See The Character Stops Following the Microphone.

The Microphone Is in Use by Your Game

Your game records that microphone through FMOD, for voice chat for instance, and FMOD runs one recording of a microphone at a time. The Console says so, FMOD Microphone In Use by the Game.

  • Your game already recorded it, so the bridge left it alone, since starting its own would have stopped your game's.
  • Your game started recording it while the bridge did, which stopped the bridge's recording and ended the character's line. The bridge leaves your game's recording alone.

Either way, hand your game's recording to the bridge with FollowMicrophone, in place of the FMOD Microphone or StartMicrophone.

The Microphone Has No Permission

On Android, the app has not been given permission to use the microphone, so the bridge did not start recording. The Console says so, FMOD Microphone Has No Permission.

  • With the FMOD Microphone, the player said no when it asked. It asks again each time it starts, until Android stops showing the request. From then on, the player allows the microphone in the app's settings.
  • From your own code, the bridge never asks, so ask first and call StartMicrophone once the player allows it, as On Each Platform sets out.

The Microphone Does Not Start

The Console says why, FMOD Microphone Did Not Start.

  • In a browser build, FMOD can't record a microphone. Start the microphone in builds for other platforms only.
  • FMOD could not start recording, and the Console names what it reported. Check that the microphone works in the system's sound settings, and that no other app keeps it to itself.
  • FollowMicrophone could not read the recording it was given: the sound is not one FMOD can read, its samples are not 16-bit or floating point in one or two channels, or FMOD is not recording on that driver. Call it once your game has started recording, with the driver and the sound it passed to FMOD's recordStart.

All Sound Stops When iOS Asks for the Microphone

Unity's Prepare iOS for Recording or Force iOS Speakers When Recording is on, and the first time iOS asks the player for the microphone, it changes the app's audio in a way that stops FMOD, for the character and the rest of the game, until the app restarts. Turn both off, and set the audio session the way FMOD's own instructions for iOS say, as On Each Platform sets out.

The Character Stops Following the Microphone

The recording stopped, so the character's line ended. The Console says so, FMOD Microphone No Longer Giving Audio, and the bridge does not start or follow it again by itself.

  • A recording handed over with FollowMicrophone stopped, its microphone was disconnected, or your game started a new recording of it. Call FollowMicrophone again with the recording your game makes now.
  • A microphone started with StartMicrophone, or with the FMOD Microphone, was stopped from other code. To end the microphone from your own code, call Stop on the bridge. To record again, call StartMicrophone.

For push-to-talk, don't stop the recording while the player isn't talking. Call PauseMicrophone and ResumeMicrophone, and keep it going (see Pause and Resume a Microphone).

The Character Does Not Follow a Channel

Follow was given a channel that isn't playing, so there is no voice to follow. The Console says so, FMOD Channel Not Playing. Pass the channel the voice plays on, once it has started.

The FMOD Microphone Does Nothing

No FaceCue FMOD Bridge is on its object or above it, so it did not start. The Console says so, FMOD Microphone Has No Bridge. Add the bridge to the character, or assign one to the FMOD Microphone's Bridge.

The Live Speaker Microphone Does Not Record

With Disable Unity Audio on, Unity has no microphone, so the Live Speaker Microphone example cannot record. The Console says so, Microphone Not Available. Use the FMOD Microphone, which records through FMOD, or turn Disable Unity Audio off.

Without the Bridge

The bridge is the way to play FMOD lines. A line can also be played on the face from a script of your own, which is a cruder route: the face plays the line's baked cues, but the live modes can't follow it, a line whose cues have not loaded yet does not play, and the script has to end each line itself. It is kept here for reference.

Speak, on the FmodSpokenLine script below, is called from wherever your game starts the line, with the event it started and the line's key:

// On the script that plays your dialogue: the FmodSpokenLine on
// the character who says the line
public FmodSpokenLine spokenLine;

// Where the line's event starts, such as PlayDialogue in FMOD's
// Programmer Sounds example
dialogueInstance.start();
spokenLine.Speak(dialogueInstance, key);
dialogueInstance.release();
//--------------------------------------------------------------------
//
// Plays a line on a FaceCue character while its voice plays through
// FMOD, with the mouth following the voice's own position in FMOD.
//
// Your game starts the line's FMOD event, for instance the way FMOD's
// Programmer Sounds example plays a line from its key. This script
// finds the line's cues by the same key and tells FaceCue where the
// voice is, each frame, until the voice ends.
//
//--------------------------------------------------------------------

using FMOD.Studio;
using Firecrest.Systems.FaceCue;
using UnityEngine;

// Run before FaceCue, so it reads this frame's time
[DefaultExecutionOrder(-1000)]
public class FmodSpokenLine : MonoBehaviour, IAudioTimeSource
{
    public FaceCueBrain brain;

    // FaceCue reads the line's time from here
    public float AudioTime { get; private set; }

    EventInstance _event;
    IDriveHandle _line;
    bool _voiceHeard;

    public void Speak(EventInstance dialogueEvent, string key)
    {
        // Find the line's cues by the key it was baked under
        bool found = brain.TryGetCues(key,
            out PhonemeCueData phonemes, out EmotionCueData emotions);
        if (!found) return;

        _event = dialogueEvent;
        _voiceHeard = false;
        AudioTime = 0f;

        // Play the cues on the character, timed by this script
        _line = brain.Speaker.PlayPhonemes(phonemes, emotions, this);
    }

    void Update()
    {
        // Update runs on the main thread, unlike FMOD's callbacks,
        // so FaceCue is only ever called from here
        if (_line == null) return;

        if (TryFindVoice(out FMOD.Channel voice))
        {
            // Use the voice's own position, not the event's. It starts
            // at 0 with the voice, whatever delay the event puts before
            // it, and holds while the event is paused
            voice.getPosition(out uint ms, FMOD.TIMEUNIT.MS);
            AudioTime = ms / 1000f;
            _voiceHeard = true;
        }
        else if (_voiceHeard)
        {
            // The voice has finished or was stopped. End the line with
            // the voice, since the event can run on past it
            _line.Release();
            _line = null;
        }
    }

    bool TryFindVoice(out FMOD.Channel voice)
    {
        voice = default;
        if (!_event.isValid()) return false;

        var result = _event.getChannelGroup(out FMOD.ChannelGroup group);
        if (result != FMOD.RESULT.OK) return false;

        return FindIn(group, out voice);
    }

    // Look through the event's channel groups for the voice
    static bool FindIn(FMOD.ChannelGroup group, out FMOD.Channel voice)
    {
        voice = default;

        group.getNumChannels(out int channels);
        if (channels > 0)
            return group.getChannel(0, out voice) == FMOD.RESULT.OK;

        group.getNumGroups(out int groups);
        for (int i = 0; i < groups; i++)
        {
            group.getGroup(i, out FMOD.ChannelGroup child);
            if (FindIn(child, out voice)) return true;
        }
        return false;
    }
}