Adding Personality to Text to Speech: Shy and Cat Speech

· 9 min read

Also in: 日本語한국어简体中文PortuguêsEspañolFrançaisDeutschРусский

Text to speech has gotten good. The voices sound real, and you can pick a tone before you talk, so a line comes out happy, sad or whispered. But even a good voice reading a clean sentence sounds like someone reading. People don't talk in clean sentences, and characters have quirks.

So I started going past tone and changing the words themselves. The first thing I built is Shy, which puts the hesitations and stutters back into what you say. It's an algorithm I wrote, not an AI rewriting your words, and it changes with the language. A second feature grew out of it, and that one comes later in the post. Here's how it works.

An algorithm for sounding nervous on purpose

The idea was to write an algorithm that makes you sound nervous on purpose, and let you pick how much. In the app that's the Shy tone in AI Voice, with three levels: Slightly, Balanced and Full. It depends on the language, because people don't hesitate the same way in Japanese as in English.

The algorithm runs on your PC in a fraction of a millisecond. It doesn't try to understand what you said. It only checks things like whether a word starts with "th" or a sentence opens on "Wait", and for what it does, that's enough. Speech to text writes down what you said, the algorithm touches that text, and the voice says the result. Your screen always shows the clean version.

Shy

Why

Speech to text is built to produce clean text. That's good for dictation and bad for sounding like a person. The "um" gets smoothed out, a repeated word becomes one word, and a stutter never makes it through. So the voice reads your line like a newsreader, even if you said it nervously. Most of what makes speech sound like a person is exactly what transcription throws away.

Shy puts it back. The "um", the restart, the stutter on the first word, the trailing off. The voice switches to a shy delivery too, quieter and less sure. It also sounds less like AI, since perfectly fluent speech is the main giveaway.

There's another reason. If you talk online with text to speech, there's a decent chance you're a bit shy about your voice. I was. A shy tone fits that person, and in a conversation it's just fun. People react to "I-I wasn't sure you'd come" very differently from the flat version.

What it does

In AI Voice, pick Shy in the Emotion strip on the Speak tab. A pill under it sets how much: Slightly, Balanced or Full.

You said
I wasn't sure you'd come. Do you want to play together?
Slightly
Um, I wasn't sure you'd come. Do you want to play together?
Balanced
I-I wasn't sure you'd come. Uh, do you want to play together?
Full
I-I wasn't sure you'd come. Um, do you, do you want to play together?
Real output from the app. It comes out a little different each time.

Shy has six moves. Each one only adds to what you said:

Here's what happens to each sentence. First: does this level touch it at all? Slightly only touches every other one, counted across takes, so quick replies alternate between touched and clean. Balanced and Full touch every sentence.

Then the opener: a filler, a stutter, or nothing. The limits here came from listening. Never two sentences in a row that open on a filler. Never a filler before "Wait" or "Oh", because nobody says "um, wait". Never a stutter on "okay" or "yeah". Below Full, never a filler on top of an opening stutter.

Then maybe one more move: a filler in the middle, a restart, or a pause at a comma. Then maybe a trail-off, never twice in a row, and never on the last sentence on Fast, since that engine stops short instead of fading. Then the tag, and a note of what it did, so the next sentence does something else. That memory is why the same line keeps coming out differently:

Take 1
Uh, okay, I'll go first.
Take 2
Okay, I-I'll go first.
Take 3
Um, okay, I'll go first...
Take 4
Okay, uh, I'll go first.
Take 5
Okay, I-I'll go first.
The same line five times in a row, at Balanced.

The algorithm

All of that is one loop. It goes one sentence at a time and remembers what it did last.

How Shy handles one sentence Each sentence is handled on its own. First, does this level touch it: Slightly only touches every other sentence, and a skipped one keeps just the shy tag. Then the opener: a filler, a stutter on the first word, or nothing. Then maybe a second move: a filler in the middle, a restart or a pause. Then maybe a trail-off, never on the last sentence on Fast. Then the tag, shy or nervous. Then it remembers what it did, so the next sentence does something else. 1Next sentenceEach one on its own 2This level's turn?Slightly: every other one 3The openerUm, a stutter, or nothing 4A second moveMid filler, restart or pause 5Trail off?Never the last line on Fast 6Tag it[shy], sometimes [nervous] 7RememberNo move twice in a row Skiptag only next sentence
One sentence at a time. The memory at the end is why the same line comes out differently each take.

The three levels change the odds per sentence:

SlightlyBalancedFull
Sentences touchedevery otherevery oneevery one
Stutter50%55%always
Filler50%55%85%
A second moveno35%45%
Restartno15%25%
Trail offno12%30%
Pause at a commano8%15%
Double stutter (I-I-I)nono15%
Giggle, throat clearnono30%, 10%
Giggles and throat clears only play on Ultra realistic.

Every language hesitates differently

Shy has a version per language, with its own fillers and its own idea of a stutter. English repeats the first sound. Japanese repeats the first kana. Chinese repeats the first character with a comma. Korean the first syllable. Russian stutters with a hyphen, like in a novel.

LanguageFillersExample
EnglishUm, uhTh-thanks, uh, for waiting.
Japaneseetto, ano, sono (えっと、あの、その)きょ、今日は一緒に遊べて楽しかった。 "today was fun playing together"
Chinesenàge, e, en, jiùshì (那个、呃、嗯、就是)等,等等,你要走了吗? "wait, are you leaving already?"
Koreaneum, eo, jeogi, geuge (음, 어, 저기, 그게)저, 저기요, 혹시 같이 놀아도 돼요? "excuse me, can I play with you?"
Russiannu, e-e, m-m (Ну, Э-э, М-м)П-привет, я тут новенький. "hi, I'm new here"
GermanÄhm, äh, alsoH-hallo, äh, ich bin neu hier. "hi, I'm new here"
FrenchEuh, bah, ben, enfinS-salut, je suis nouveau ici. "hi, I'm new here"
SpanishEh, pues, bueno, mmmH-hola, pues, soy nuevo aquí. "hi, I'm new here"
PortugueseÉ, hum, então, tipoO-oi, tipo, eu sou novo aqui. "hi, I'm new here"
Every example is engine output.

The tricky ones were fillers that are also words. In Chinese, nàge (那个) is the most common hesitation, the "um", but it also means "that". If the voice rushes the pause, nàge... rén duō ("um... lots of people") turns into nàge rén duō, "that person". So nàge is only allowed before words like wǒ and nǐ ("I" and "you"). Japanese ano (あの) has the same problem (ano purezento is "that present"), and Russian eto (это) blurs into eto ya, "it's me". Each one has its own check.

Japanese has one more catch. To stutter on 今日 ("today") you need to know it's read kyō, and the text doesn't say. So Shy carries a list of common words and their readings. A word not on the list gets a filler instead of a guess.

Cat speech

Why

Once Shy worked, I wanted to try the same idea on a way of talking that is pure character. One of my favorite character tropes in anime is the cat person, "neko" in Japanese. They say "nya", which I and a lot of avid anime watchers find cute and endearing (those of us who watch with subtitles instead of the dub, anyway), and it colors the conversation in a way that never comes across outside Japanese. Sentences end in nya. A "na" in the middle of a word turns into "nya". A surprised little "nya!" opens a line. Japanese anime has developed this further than anywhere else: there are decades of conventions, and native speakers hear right away whether it's done right.

Chinese has its own version. The cat girl (猫娘, māoniáng) ends her sentences in "miao" (喵), and there's a well-known pun where miào (妙, "wonderful") becomes miāo because they sound alike. But the conventions differ. In Japanese the cat sound lives inside the words. In Chinese it sits at the end of the sentence, like a particle. Korean doesn't really have this style, and when I tried an English version it just sounded weird. So cat speech is Japanese and Chinese only. It's called Neko (ネコ) or Miao Miao (喵喵), under Speech style on the Speak tab, and it shows up when the app is in one of those languages with a matching voice.

Japanese
そんなことないです → そんにゃことにゃいですにゃsonna koto nai desu ("no, not at all") → sonya koto nyai desu nya
Chinese
太妙了! → 太喵了喵!tài miào le ("that's wonderful!") → tài miāo le miāo
Full intensity. Japanese swaps sounds inside the words (na → nya). Chinese adds miao at the end and swaps one pun (miào → miāo).

The algorithm

Both languages use the same algorithm with a different table.

How cat speech handles one line The engine reads the script of the line: kana means the Japanese table, Chinese characters only means the Chinese table, anything else passes through unchanged. It rolls the dice: a line that sits out passes through. It changes the ending from its table. On Full it swaps sounds inside words and may add an interjection. Then it undoes every edit and compares with what you said. If anything differs, your words pass through unchanged. If it matches, the cat line is said. 1Which script?Kana or Chinese characters 2Roll the diceネコ always, 喵喵 most lines 3The endingね → にゃ, 吗 → 喵, or add 4Puns inside wordsFull only: な → にゃ, 妙 → 喵 5An interjectionにゃっ! on an exclamation 6Undo and compareEvery edit knows its undo 7Said as a catにゃ / 喵 Your words unchanged
Three ways out to the right, all of them your words unchanged. The check at step 6 runs on every line.

It first looks at the script. Kana means the Japanese table. Only Chinese characters means the Chinese table. Anything else, like an English line or a mix, passes through untouched. Then it rolls. Neko fires on every line, Miao Miao on most of them, so there isn't a miao on every single sentence.

Next comes the ending, which does most of the work. The last word is matched against a table, top to bottom, and the first row that fits wins.

Japanese (Neko)Chinese (Miao Miao)
WhereInside words and at the endAt the end of the sentence
EndingsThe particles ne, yo and ka become nya (ね → にゃ, よ → にゃ, か → かにゃ), polite desu gets nya (です → ですにゃ), anything else just adds nyaThe question particles ma and ne become miao (吗 → 喵, 嘛 → 喵, 呢 → 喵), anything else just adds miao
Greetingskonnichiwa → konnichi-nya (こんにちは → こんにちにゃ), okaeri ("welcome home") → okaeri-nyanone
Inside words (Full)naruhodo ("I see") → nyaruhodo, minna ("everyone") → minnya, nai ("not") → nyai, and na → nya, nu → nyu, ne → nye in any word, up to 3 per linemiào ("wonderful", 妙) → miāo (喵), shénme ("what", 什么) → shén-miāo (什喵), 1 per line
Interjections (Full)nya! (にゃっ!) on an exclamation, nya? on a question, unya~ anywheremiao! (喵!) on an exclamation, miao? on a question, miao-wu (喵呜) anywhere
Fires onevery line8 lines in 10 (Light), 19 in 20 (Full)
Nevera na right after a verb, as in iku na (行くな, "don't go")a line with no Chinese characters
Light only changes endings. Full adds the puns inside words and the interjections.

The na row needs care. Iku na (行くな) means "don't go". Turn that na into nya and you get iku nya (行くにゃ), which sounds like "I'm going". So the algorithm checks what's before the na, and leaves it alone after a verb. The same guard sits in the inside-the-word table too, because testing found a back door there. The no → nyo swap (の → にょ) was in the table at first and got cut after a corpus test: it hit every kono and sono ("this" and "that") and every question ending in no, and sounded like a lisp, not a cat.

On Full, a line can also open with an interjection. Nya! only fires on a sentence ending in an exclamation mark, nya? only on a question. Each has a fire rate and a budget, so a line gets at most two insertions and three sound swaps, and the same interjection never comes twice in a row.

The safety check

Shy only adds words, so it can't change what you meant. Cat speech changes words, so every line is checked.

Every edit carries its own undo. "ne became nya" is stored with "nya was ne". Before the line is sent, the engine undoes all its edits on its own output and compares with what you said, character by character. If they match, the cat line goes to the voice. If anything is off, there's a bug in the table, so your original words go instead and the bad row shows up in my dashboard. That check is why I'm fine shipping the tables as data I can fix without a release.

Why an algorithm

I tested the AI route before building this, and here's why I didn't go with it.

Where it runs

Both run on your PC, between speech to text and text to speech. Nothing extra is sent anywhere. Shy also works on what you type in Type mode. Cat speech is for what you say out loud; when you type, write the nya yourself. Saved Lines are always said exactly as written.

If a line ever comes out wrong, tell me through Feedback in the app. Most of it is one line in a table, so a fix is quick, and the check means a bad row never changes what you said.