Baking from Code¶
Baking, transcribing, synthesising and converting from a script, with the windows' own settings.
Everything the Cue Baker and the Speech Production Tools do by hand, a script can do too. Bake a folder after an import, bake a line again after its transcript changed, speak a line again after its text changed, transcribe a folder of recordings overnight, or move a folder of takes onto a character's voice. The calls live on one static class, FaceCueBaking, in the Firecrest.Systems.FaceCue.Editor namespace.
Each tool has one call for each of its window's two modes, so a script reads like the Mode row it stands in for:
| Tool | Single | Batch |
|---|---|---|
| The Cue Baker | Bake |
BakeBatch |
| Recognize Speech | Transcribe |
TranscribeBatch |
| Synthesize Speech | Synthesize |
SynthesizeBatch |
| Convert Speech | Convert |
ConvertBatch |
Create Voice has one call, CreateVoice, whose reference is one clip or several, the tab's two modes. Registered Voices has calls of its own, which list the voices and set a voice's native languages.
How a Call Works¶
The window's saved settings are the starting point. Every call reads what its window last saved: a bake from the Cue Baker, a transcription from the Recognize Speech tab, a synthesis from the Synthesize Speech tab, a conversion from Convert Speech, a voice from Create Voice. An options object changes any of those for that one call, and a setting you leave unset keeps the saved value. So the usual pattern is to tune the window once, by hand, and let the script do the repetition. The right-hand settings panes are not part of the options: a call uses what they have saved, as the window does.
A call writes what the window writes. A call and a window run with the same settings produce the same files.
The calls are for the editor. They run on the main thread and return when the work is done, with no progress bar. Put the script in an Editor folder, or an assembly that only builds for the editor.
Nothing is downloaded. A call that needs a model you have not installed stops at once with an InvalidOperationException, and the message names what to download in the Cue Baker's Setup. The same goes for anything else the call cannot work with, a missing audio file, a language the strategy does not read, a voice that does not exist: the exception comes before any work is done, and its message says what to change.
A model stays loaded after a call, so the next call skips the load, which takes several seconds for the larger models. See Freeing the Models.
Choices That Carry Their Settings¶
In the windows, some settings sit beneath another one. Picking a strategy in the Cue Baker brings up its language and its recognizer. Picking a CSV index as the transcript source brings up a CSV picker. Turning Output Beside Source off brings up a folder.
The options follow the same shape. A choice like that is not a plain value: it is built by a method named after the option you would pick in the window, and the settings beneath it are that method's arguments.
Strategy = CueBakeStrategy.Accurate("es", RecognizerKind.TranscriptDecoder, dialect: "River Plate"),
Transcript = TranscriptSource.CsvIndex("Assets/Dialogue/lines.csv"),
Output = OutputLocation.Folder("Assets/Cues/Spanish"),
Two things follow from that:
- A setting goes only where it is read. There is nowhere to give the Universal strategy a language, or a .txt transcript a CSV path, because neither reads one. Your editor's autocomplete lists exactly the settings each choice has.
- Whatever a choice leaves out keeps the saved value, the same rule as an option left unset.
CueBakeStrategy.Accurate()bakes with the Accurate strategy in the language, recognizer and dialect the Cue Baker saved, andCueBakeStrategy.Accurate("fr")changes only the language. That is what the window does when you switch strategy: each one comes back with its own last settings.
| Choice | Built with | In the window |
|---|---|---|
CueBakeStrategy |
Accurate(language, recognizer, dialect), MultilingualFreeDecode(), MultilingualTranscript(language), Universal() |
The Cue Baker's Strategy and the rows beneath it |
TranscriptSource |
PlainText(text), TxtSidecar(), CsvIndex(csvPath) |
The Cue Baker's transcript Source |
TranscribeStrategy |
Specialized(), Multilingual(language) |
Recognize Speech's Strategy and Language |
TranscriptOutput |
TxtSidecar(location), CsvIndex(location, existingIndex) |
Recognize Speech's Format and the output beneath it |
SpeechLine, SpeechLines |
See Synthesising | Synthesize Speech's Source |
LanguageCoaching |
None(), Standard(), Voice(strength) |
Synthesize Speech's Language Coach and Coaching |
VoiceReference |
Clip(audioFilePath), Clips(audioFilePaths) |
Create Voice's Voice Reference, its Mode on Single or Multiple |
OutputLocation |
BesideSource(), Folder(path), File(path) |
Output Beside Source and the path under it |
Existing Files¶
Every call that writes a file takes an ExistingFiles argument, and it has no default. A cue file or a transcript can hold edits made by hand, so whether a run may replace one is a choice the script states every time, rather than one it inherits.
| Value | What it does |
|---|---|
ExistingFiles.Skip |
Keeps the file that is there and writes nothing in its place |
ExistingFiles.Overwrite |
Replaces it. A cue file or a transcript is first copied into a backup folder beside it. Audio is replaced without a backup |
ExistingFiles.KeepAndIterate |
Keeps the file and saves the new one beside it under a numbered name. Synthesize, Convert and CreateVoice do this. Every other call treats it as Skip |
Baking¶
public static CueBakeResult Bake(string audioFilePath, ExistingFiles existingFiles,
BakeOptions options = null)
public static IReadOnlyList<CueBakeResult> BakeBatch(string audioFolderPath, ExistingFiles existingFiles,
BakeOptions options = null)
| Parameter | What it does |
|---|---|
stringaudioFilePath |
For Bake: the clip's audio file, WAV, OGG, MP3 or FLAC, as a path under Assets/ or an absolute path |
stringaudioFolderPath |
For BakeBatch: the folder holding the audio. Only its top level is read |
ExistingFilesexistingFiles |
What to do with a clip that already has a cue file. See Existing Files |
BakeOptions = nulloptions |
Settings that replace the Cue Baker's saved ones for this call. Leave it out to bake with the saved settings |
BakeBatch pairs clips with their transcripts the way Batch Baking does, from a TXT file beside each recording or from a CSV index. One clip's failure does not stop the rest.
// Single mode: one clip, with the Cue Baker's saved settings
FaceCueBaking.Bake("Assets/Audio/intro_01.wav", ExistingFiles.Overwrite);
// Batch mode: every clip in a folder, its transcripts read from the TXT files beside the audio
FaceCueBaking.BakeBatch("Assets/Audio/Chapter1", ExistingFiles.Skip,
new BakeOptions { Transcript = TranscriptSource.TxtSidecar() });
Bake Options¶
| Member | What it does |
|---|---|
CueBakeStrategyStrategy |
How the cues are produced, with the settings beneath it. See Strategy |
TranscriptSourceTranscript |
Where each clip's transcript is read from. See Transcript |
LanguageSpans?LanguageSpans |
How parts of a transcript tagged as another language are read: Ignore, SinglePass or PerLanguage |
bool?UseTranscript |
Whether a strategy that reads the audio alone also reads the transcript, for its tags. false leaves it unread. A transcript decoder always reads it, so false with one is refused |
BakingBackend?Backend |
|
OutputLocationOutput |
OutputLocation.BesideSource() writes each cue file beside its audio, OutputLocation.Folder(path) into one folder |
stringClipName |
The name the cue file is written under. BakeBatch does not accept it |
int?BackupVersions |
How many earlier backups an overwrite keeps. 0 keeps every one |
Strategy¶
The strategies are described in Recognizers.
| Built with | What it bakes with |
|---|---|
CueBakeStrategy.Accurate(language, recognizer, dialect) |
The recognizer built for the language. language is one of the ten tuned languages, recognizer is RecognizerKind.TranscriptDecoder or RecognizerKind.FreeDecoder, and dialect is one of the language's dialects, or "" for its default. The language's first recognizer of that kind in the Recognizer dropdown is used. A language with none of that kind uses its first recognizer instead, and the Console says so |
CueBakeStrategy.MultilingualFreeDecode() |
One model for many languages, from the audio alone |
CueBakeStrategy.MultilingualTranscript(language) |
One model for many languages, following the transcript. language is any language this mode reads, or FaceCueBaking.AutoDetect to detect each clip's language from its transcript |
CueBakeStrategy.Universal() |
The audio alone, with no language. It needs the OVRLipSync integration |
Every argument can be left out, and then keeps what the Cue Baker saved. The codes and dialects are listed under Language & Dialect Codes.
Transcript¶
| Built with | Where the transcript comes from |
|---|---|
TranscriptSource.PlainText(text) |
The text you give, used as it is. BakeBatch does not accept it, since a folder bake reads each clip's own transcript |
TranscriptSource.TxtSidecar() |
A TXT file beside each recording, with the clip's name |
TranscriptSource.CsvIndex(csvPath) |
A row of a CSV index. csvPath names the CSV, or is FaceCueBaking.AutoDetect for the one found beside the audio, the CSV picker's Auto. Left out, it keeps the CSV the Cue Baker saved |
A bake has no row picker. Each clip reads the row whose clip id is its own file name, in single mode as in batch, so baking one clip from a CSV index is a matter of naming the CSV.
Every option set, for one Spanish clip:
var options = new BakeOptions
{
Strategy = CueBakeStrategy.Accurate("es", RecognizerKind.TranscriptDecoder, dialect: "River Plate"),
Transcript = TranscriptSource.PlainText("Lo encontré ahà en la calle."),
LanguageSpans = LanguageSpans.PerLanguage,
Backend = BakingBackend.Cuda,
Output = OutputLocation.Folder("Assets/Cues/Spanish"),
ClipName = "street_01",
BackupVersions = 5,
};
FaceCueBaking.Bake("Assets/Audio/es_street_01.wav", ExistingFiles.Overwrite, options);
And for a folder whose clips are in several languages, each detected from its row of a CSV index:
var options = new BakeOptions
{
Strategy = CueBakeStrategy.MultilingualTranscript(FaceCueBaking.AutoDetect),
Transcript = TranscriptSource.CsvIndex("Assets/Dialogue/lines.csv"),
Backend = BakingBackend.Cuda,
Output = OutputLocation.BesideSource(),
BackupVersions = 5,
};
FaceCueBaking.BakeBatch("Assets/Audio/Chapter1", ExistingFiles.Skip, options);
Bake Results¶
Each CueBakeResult names the clip's AudioPath, the CueFilePath written or kept, a Status and, when the clip was not baked, a Message saying why. Status is one of Baked, KeptExisting, NoTranscript (the recognizer reads against a transcript and the clip has none) or Failed. ToString() puts all of it on one line, ready for a log.
CueBakeResult result = FaceCueBaking.Bake("Assets/Audio/intro_01.wav", ExistingFiles.Skip);
Debug.Log(result.CueFilePath);
foreach (CueBakeResult r in FaceCueBaking.BakeBatch("Assets/Audio/Chapter1", ExistingFiles.Skip))
{
if (r.Status != CueBakeStatus.Baked) Debug.LogWarning(r);
}
Transcribing¶
public static TranscribeResult Transcribe(string audioFilePath, ExistingFiles existingFiles,
TranscribeOptions options = null)
public static IReadOnlyList<TranscribeResult> TranscribeBatch(string audioFolderPath, ExistingFiles existingFiles,
TranscribeOptions options = null)
| Parameter | What it does |
|---|---|
stringaudioFilePath |
For Transcribe: the clip's audio file |
stringaudioFolderPath |
For TranscribeBatch: the folder holding the audio. Only its top level is read |
ExistingFilesexistingFiles |
What to do with a clip that already has a transcript. See Existing Files |
TranscribeOptions = nulloptions |
Settings that replace the Recognize Speech tab's saved ones for this call |
The transcript is written where the tab would write it, a TXT file or a row in a CSV index, and the result also hands it back as text. TranscribeBatch reads several clips at once, which on a graphics card is faster than transcribing them one by one.
// Single mode: one clip, with the tab's saved settings
FaceCueBaking.Transcribe("Assets/Audio/intro_01.wav", ExistingFiles.Skip);
// Batch mode: every clip in a folder, each language detected from its audio
FaceCueBaking.TranscribeBatch("Assets/Audio/Chapter1", ExistingFiles.Skip,
new TranscribeOptions { Strategy = TranscribeStrategy.Multilingual(FaceCueBaking.AutoDetect) });
Transcribe Options¶
| Member | What it does |
|---|---|
TranscribeStrategyStrategy |
Which model reads the audio, with its language. See Strategy and Language |
TranscriptOutputOutput |
What each transcript is written as, and where. See Output |
BakingBackend?Backend |
The hardware the model runs on |
int?BackupVersions |
How many earlier backups an overwrite keeps. 0 keeps every one |
int?BatchSize |
How many clips are read at once, 1 to 16. Higher is faster and uses more graphics memory. Only TranscribeBatch accepts it |
Strategy and Language¶
| Built with | Which model reads the audio |
|---|---|
TranscribeStrategy.Specialized() |
The English model: English only, about twice as fast, with the same English transcripts. See Recognize Speech |
TranscribeStrategy.Multilingual(language) |
The model for every supported language. language is a code the model reads, or FaceCueBaking.AutoDetect to detect each clip's language. Left out, it keeps the tab's saved language |
Output¶
| Built with | What is written |
|---|---|
TranscriptOutput.TxtSidecar(location) |
One TXT file per clip, named after it. location is OutputLocation.BesideSource() or OutputLocation.Folder(path) |
TranscriptOutput.CsvIndex(location, existingIndex) |
One row per clip in a CSV index. location is OutputLocation.BesideSource(), which writes a CSV named after the audio's folder, or OutputLocation.File(path). A CSV that does not exist yet is created. existingIndex is ExistingIndex.Merge, which keeps the rows already there, or ExistingIndex.Replace, which writes the index from this run alone. Only TranscribeBatch accepts it, since one clip always merges its own row |
Either argument can be left out, and then keeps what the tab saved.
Every option set, for one French clip:
var options = new TranscribeOptions
{
Strategy = TranscribeStrategy.Multilingual("fr"),
Output = TranscriptOutput.TxtSidecar(OutputLocation.Folder("Assets/Transcripts/French")),
Backend = BakingBackend.Cuda,
BackupVersions = 5,
};
FaceCueBaking.Transcribe("Assets/Audio/fr_intro_01.wav", ExistingFiles.Overwrite, options);
And for a folder written into one CSV index:
var options = new TranscribeOptions
{
Strategy = TranscribeStrategy.Multilingual(FaceCueBaking.AutoDetect),
Output = TranscriptOutput.CsvIndex(OutputLocation.File("Assets/Dialogue/lines.csv"), ExistingIndex.Merge),
Backend = BakingBackend.Cuda,
BackupVersions = 5,
BatchSize = 8,
};
FaceCueBaking.TranscribeBatch("Assets/Audio/Chapter1", ExistingFiles.Skip, options);
Transcribe Results¶
Each TranscribeResult carries the clip's AudioPath, the TranscriptPath that holds its transcript, the Text itself, a Status and a Message. Status is Transcribed, KeptExisting, NoTranscript (nothing usable was heard) or Failed.
TranscribeResult line = FaceCueBaking.Transcribe("Assets/Audio/intro_01.wav", ExistingFiles.Skip);
Debug.Log(line.Text);
foreach (TranscribeResult r in FaceCueBaking.TranscribeBatch("Assets/Audio/Chapter1", ExistingFiles.Skip))
{
if (r.Status == TranscribeStatus.NoTranscript) Debug.LogWarning(r);
}
Synthesising¶
public static SynthesizeResult Synthesize(SpeechLine line, ExistingFiles existingFiles,
SynthesizeOptions options = null)
public static IReadOnlyList<SynthesizeResult> SynthesizeBatch(SpeechLines lines, ExistingFiles existingFiles,
SynthesizeOptions options = null)
| Parameter | What it does |
|---|---|
SpeechLineline |
For Synthesize: the one line to speak. See below |
SpeechLineslines |
For SynthesizeBatch: the lines to speak. See below |
ExistingFilesexistingFiles |
What to do when a line's audio is already there. Synthesize can keep it and number the new take. See Existing Files |
SynthesizeOptions = nulloptions |
Settings that replace the Synthesize Speech tab's saved ones for this call |
The line is built the way the tab's Source row picks it:
| Built with | What is spoken | The wav is named after |
|---|---|---|
SpeechLine.PlainText(text, fileName) |
The text you give. Transcript tags are read as the tab reads them | The first words of the text |
SpeechLine.TxtFile(path, fileName) |
The line in a TXT file | The TXT file |
SpeechLine.CsvRow(csvPath, clipId, fileName) |
The line in the CSV row with that clip id | The clip id |
SpeechLines.TxtFolder(path) |
Every TXT file in a folder, one line per file | Each TXT file |
SpeechLines.CsvIndex(csvPath) |
Every row of a CSV index | Each row's clip id |
fileName is optional, and names the wav instead. A batch names each file after its line, so the audio pairs with its transcript for a bake straight away.
// Single mode: a line given as text, the line in a TXT file, or one row of a CSV index
FaceCueBaking.Synthesize(SpeechLine.PlainText("Keep the door closed until I come back."), ExistingFiles.KeepAndIterate);
FaceCueBaking.Synthesize(SpeechLine.TxtFile("Assets/Dialogue/captain_01.txt"), ExistingFiles.Overwrite);
FaceCueBaking.Synthesize(SpeechLine.CsvRow("Assets/Dialogue/scene_03.csv", "captain_03"), ExistingFiles.Overwrite);
// Batch mode: every line in a folder of TXT files, or every row of a CSV index
FaceCueBaking.SynthesizeBatch(SpeechLines.CsvIndex("Assets/Dialogue/scene_03.csv"), ExistingFiles.Skip);
Voices¶
A call names its voice with Voice, in one of three ways:
string? SynthesizeOptions.Voice { get; set; }
string? ConvertOptions.Voice { get; set; }
| Value | Which voice speaks |
|---|---|
"Captain #1" |
One of your registered voices, by its name exactly as Registered Voices lists it. That name is the voice file's name without its extension |
"Male Sample" |
The voice FaceCue comes with |
"Assets/Voices/Extras/Old Guard.fcv1" |
A voice file anywhere on disk, by its path |
Leave Voice out to use the voice the tab has selected. A name that matches no voice stops the call, and the message lists the voices there are.
Male Sample Is for Trying Things Out
A call that speaks with Male Sample writes a warning to the Console, the same one the tab shows before it synthesises. Turning the warning off in the Speech Production Tools turns it off here too.
Synthesize Options¶
| Member | What it does |
|---|---|
stringVoice |
The voice that speaks. See Voices |
stringLanguage |
A language code, or FaceCueBaking.AutoDetect to detect it from the text. See Language & Dialect Codes |
LanguageCoachingLanguageCoach |
LanguageCoaching.None(), LanguageCoaching.Standard() or LanguageCoaching.Voice(strength), where strength is CoachingStrength.Light, Firm or Full, and left out keeps the tab's Coaching. See Language Coach |
int?Seed |
The number that fixes the random choices in a take. The same seed, voice and text give the same audio on the same machine |
BakingBackend?Backend |
The hardware the model runs on |
OutputLocationOutput |
OutputLocation.BesideSource() writes each wav beside the file its line was read from, OutputLocation.Folder(path) into one folder. A line given as text has no file to sit beside, so it takes a folder |
Every option set, for one row of a CSV index:
var options = new SynthesizeOptions
{
Voice = "Captain #1",
Language = "en",
LanguageCoach = LanguageCoaching.Voice(CoachingStrength.Firm),
Seed = 7,
Backend = BakingBackend.Cuda,
Output = OutputLocation.Folder("Assets/Audio/Scene3"),
};
FaceCueBaking.Synthesize(SpeechLine.CsvRow("Assets/Dialogue/scene_03.csv", "captain_03", fileName: "captain_03_take2"),
ExistingFiles.KeepAndIterate, options);
And for a folder of TXT files, each wav written beside its line:
var options = new SynthesizeOptions
{
Voice = "Captain #1",
Language = FaceCueBaking.AutoDetect,
LanguageCoach = LanguageCoaching.Standard(),
Seed = 7,
Backend = BakingBackend.Cuda,
Output = OutputLocation.BesideSource(),
};
FaceCueBaking.SynthesizeBatch(SpeechLines.TxtFolder("Assets/Dialogue/Scene3"), ExistingFiles.Skip, options);
Synthesize Results¶
Each SynthesizeResult carries the line's Name, the AudioPath written or kept, a Status, Synthesized, KeptExisting or Failed, and a Message when it failed.
SynthesizeResult take = FaceCueBaking.Synthesize(SpeechLine.PlainText("Hold the gate."), ExistingFiles.KeepAndIterate);
Debug.Log(take.AudioPath);
foreach (SynthesizeResult r in FaceCueBaking.SynthesizeBatch(SpeechLines.CsvIndex("Assets/Dialogue/scene_03.csv"), ExistingFiles.Skip))
{
if (r.Status == SynthesizeStatus.Failed) Debug.LogWarning(r);
}
Converting¶
public static ConvertResult Convert(string audioFilePath, ExistingFiles existingFiles,
ConvertOptions options = null)
public static IReadOnlyList<ConvertResult> ConvertBatch(string audioFolder, ExistingFiles existingFiles,
ConvertOptions options = null)
| Parameter | What it does |
|---|---|
stringaudioFilePath |
For Convert: the recording, WAV, OGG, MP3 or FLAC, as a path under Assets/ or an absolute path |
stringaudioFolder |
For ConvertBatch: the folder of recordings. Only its top level is read |
ExistingFilesexistingFiles |
What to do when a recording's converted clip is already there. Convert can keep it and number the new one. ConvertBatch treats KeepAndIterate as Skip, so a second run converts only what is new |
ConvertOptions = nulloptions |
Settings that replace the Convert Speech tab's saved ones for this call |
Convert Speech keeps the performance and changes the voice: the timing, the stress and the pauses carry across, and the converted clip speaks in the voice you name. Each clip is named after its recording with a suffix added, or with the file name you give, and written beside the recording or into a folder. One recording's failure does not stop a batch.
// Single mode: one take, into a registered voice
FaceCueBaking.Convert("Assets/Audio/Takes/door_01.wav", ExistingFiles.Overwrite,
new ConvertOptions { Voice = "Captain #1" });
// Batch mode: every take in a folder, written into a folder of their own
FaceCueBaking.ConvertBatch("Assets/Audio/Takes", ExistingFiles.Skip,
new ConvertOptions { Voice = "Captain #1", Output = OutputLocation.Folder("Assets/Audio/Captain") });
A converted clip knows which recording it was made from. A batch leaves out a converted clip whose recording is in the same folder, so clips written beside their recordings are never converted a second time, and it has no result for them. A converted clip with no recording beside it is converted like any other, so a folder of one character's clips can be moved into another voice.
Convert Options¶
| Member | What it does |
|---|---|
stringVoice |
The voice the recording is converted into, named the same three ways as for synthesis. See Voices |
int?Seed |
The number that fixes the random choices in a conversion. The same seed, voice and recording give the same audio on the same machine |
BakingBackend?Backend |
The hardware the model runs on |
OutputLocationOutput |
OutputLocation.BesideSource() writes each clip beside its recording, OutputLocation.Folder(path) into one folder |
stringSuffix |
What is added to the end of the recording's name to name its clip. With "_captain", the clip converted from door_01 is named door_01_captain. A clip written beside its recording needs a suffix, since without one it would replace the recording |
stringFileName |
The clip's file name, in place of the recording's name and the suffix. Only Convert accepts it, since each clip of a folder needs a name of its own |
Left out, Voice and Seed are the ones Synthesize Speech and Convert Speech share, and Output and Suffix are the Convert Speech tab's. A call that would write a clip over the recording it is made from stops before any work.
Every option set, for one take:
var options = new ConvertOptions
{
Voice = "Captain #1",
Seed = 7,
Backend = BakingBackend.Cuda,
Output = OutputLocation.Folder("Assets/Audio/Captain"),
FileName = "captain_door_01",
};
FaceCueBaking.Convert("Assets/Audio/Takes/door_01.wav", ExistingFiles.KeepAndIterate, options);
Convert Results¶
Each ConvertResult carries the recording's SourcePath, the clip's Name, the AudioPath written or kept, a Status, Converted, KeptExisting or Failed, and a Message: why the clip failed, or that it was converted on the CPU because the chosen backend failed on it.
foreach (ConvertResult r in FaceCueBaking.ConvertBatch("Assets/Audio/Takes", ExistingFiles.Skip,
new ConvertOptions { Voice = "Captain #1", Output = OutputLocation.Folder("Assets/Audio/Captain") }))
{
if (r.Status == ConvertStatus.Failed) Debug.LogWarning(r);
}
Creating Voices¶
public static CreateVoiceResult CreateVoice(VoiceReference reference, ExistingFiles existingFiles,
CreateVoiceOptions options = null)
| Parameter | What it does |
|---|---|
VoiceReferencereference |
The recording the voice is cloned from. VoiceReference.Clip(audioFilePath) takes one clip, the tab's Single mode, and VoiceReference.Clips(audioFilePaths) takes several clips of the same speaker, its Multiple mode |
ExistingFilesexistingFiles |
What to do when a voice of that name is already there. ExistingFiles.KeepAndIterate keeps it and saves the new voice under a numbered name |
CreateVoiceOptions = nulloptions |
Settings that replace the Create Voice tab's saved ones for this call |
The voice is saved as a voice file into the folder Registered Voices lists, or the tab's own folder, so a voice made from code shows up in every voice picker. The reference is cleaned first as the tab's settings pane says, with Denoise and Speech Restoration. What makes a good reference is covered under Reference Clips.
CreateVoiceResult captain = FaceCueBaking.CreateVoice(
VoiceReference.Clip("Assets/Audio/Reference/captain.wav"), ExistingFiles.Overwrite,
new CreateVoiceOptions { Name = "Captain", NativeLanguages = new[] { "en" } });
FaceCueBaking.Synthesize(SpeechLine.PlainText("Hold the gate."), ExistingFiles.KeepAndIterate,
new SynthesizeOptions { Voice = captain.Name });
Create Voice Options¶
| Member | What it does |
|---|---|
stringName |
The voice's name, which its file is named after and Registered Voices lists it as. Left out, the voice is named after the first reference clip |
float?Exaggeration |
How animated the voice's read is, from 0 to 2, built into the voice when it is created. Lower is flat and even, higher is strongly expressive |
IReadOnlyList<string>NativeLanguages |
The languages the speaker speaks natively, main language first. An empty list saves the voice as Not Set, and new[] { FaceCueBaking.AutoDetect } detects the main language from the first reference clip. Left out, it follows the tab's Native Language mode: Auto-Detect detects, and Manual saves Not Set, since the languages picked in the tab belong to the reference picked there |
BakingBackend?Backend |
The hardware the model runs on |
OutputLocationOutput |
The folder the voice is saved into, as OutputLocation.Folder(path). Left out, it is the tab's choice |
Detecting a language needs the Multilingual ASR Transcript Generator. Without it, the voice is saved as Not Set.
Create Voice Results¶
Each CreateVoiceResult carries the voice's Name, the VoicePath saved or kept, a Status, Created or KeptExisting, the NativeLanguages saved with it, and a Message with a note on the native language, such as the one detected.
Registered Voices¶
| Member | What it does |
|---|---|
IReadOnlyList<RegisteredVoice> staticRegisteredVoices() |
The voices Registered Voices lists: Male Sample first, then each voice file in the voices folder. Read from disk on every call, so a voice created a moment ago is in it |
RegisteredVoice staticSetNativeLanguages(string voice, IReadOnlyList<string> nativeLanguages) |
Sets the languages a registered voice's speaker speaks natively, main language first, as Changing a Voice's Native Language does, and returns the voice as it now stands. voice is its name as RegisteredVoices lists it. An empty list sets it to Not Set. Male Sample's language cannot be changed |
string static read-onlyVoicesFolder |
The folder Registered Voices lists, as an absolute path. A voice file saved there can be named by its name |
Each RegisteredVoice describes one voice:
| Member | What it does |
|---|---|
string read-onlyName |
The voice's name, the one SynthesizeOptions.Voice and ConvertOptions.Voice take |
string read-onlyVoicePath |
The voice file, as an absolute path. Empty for Male Sample |
string read-onlyAssetPath |
The voice file as a path under Assets/, the form Unity's AssetDatabase calls take. Empty for Male Sample and for a voice kept outside the project |
bool read-onlyIsSample |
True for Male Sample, the voice FaceCue comes with |
bool read-onlyIsSelected |
True for the voice selected in Registered Voices, the one a call uses when it names none. No voice in the list is selected when the selection is a voice file outside the voices folder |
IReadOnlyList<string> read-onlyNativeLanguages |
The speaker's native languages, main language first. Empty when the voice is Not Set |
foreach (RegisteredVoice voice in FaceCueBaking.RegisteredVoices())
Debug.Log(voice);
FaceCueBaking.SetNativeLanguages("Captain #1", new[] { "fr", "en" });
Native languages decide when a voice is coached: a voice speaking one of its own languages is never coached, and one that is Not Set is never coached at all. See Language Coach.
Selecting the window's voice stays in the window, since a call names its voice in its options.
Removing a Voice¶
A voice is a file, so removing one is removing its file, with Unity's own calls. Registered Voices and every voice picker stop listing it at once. AssetDatabase.MoveAssetToTrash moves it to the system trash with its .meta, so the removal can be undone:
foreach (RegisteredVoice voice in FaceCueBaking.RegisteredVoices())
{
if (voice.Name == "Captain #1") AssetDatabase.MoveAssetToTrash(voice.AssetPath);
}
A voice kept outside the project has no AssetPath, and is removed like any other file, from its VoicePath. When the voice removed was the selected one, a call that names no voice speaks with Male Sample until another is selected.
Language & Dialect Codes¶
Scripts name a language by its code, shown beside each language below. Search for a language to find its code, or for a code to find its language. The same checker is on Language Support, which explains what each layer means.
The chips say which calls take the code.
| Chip | The calls that take the code |
|---|---|
| Accurate | Bake and BakeBatch, in CueBakeStrategy.Accurate and in CueBakeStrategy.MultilingualTranscript |
| Multilingual | Bake and BakeBatch, in CueBakeStrategy.MultilingualTranscript |
| Universal | None. CueBakeStrategy.MultilingualFreeDecode and CueBakeStrategy.Universal read any language, so they take no code |
| Transcript | Transcribe and TranscribeBatch, in TranscribeStrategy.Multilingual |
| Synthesis | Synthesize and SynthesizeBatch, in SynthesizeOptions.Language, and SetNativeLanguages |
A call given a code it does not take stops before any work, and the message lists the codes it does. Norwegian has two codes, "nb" and "no", and every call takes either.
Dialects belong to the Accurate strategy, and the checker lists them under their language. CueBakeStrategy.Accurate takes the name as shown there as its dialect, such as "River Plate".
Freeing the Models¶
public static int ClearModelsInMemory()
Frees every model the Cue Baker and the Speech Production Tools hold in memory, what Clear All does in the Models In Memory window, and returns how many were held. Call it when a script has finished a run and the memory is wanted back. The next call that needs a model loads it again.
FaceCueBaking.BakeBatch("Assets/Audio/Chapter1", ExistingFiles.Skip);
FaceCueBaking.ClearModelsInMemory();