Markov Chains for algorithmic text generation.

linlin's icon

Hello,

I'm looking for ressources or ideas on how to create a markov chain analysis for text generation.
Would probably be first a system to analyse a .txt file to get a probability table, and then another module to generate a text based on it.

I'm looking at the "text" and "coll" objects for now.

Is there somewhere on the web some exemples/tutorial of this kind of implementation for max?
Or some equivalent to the Rita library for processing in a max external?

yaniki's icon

Dear LINLIN

In my opinion the easiest way to construct a markov chain based on succession of words in a text will be probably based on the [js] object - in other words: instead of patching you can write JavaScript code.

On the other hand... you mentioned Rita library for Processing. Rita is a nice and robust tool and you may consider to build a mechanism for communicating between Max and Processing via OSC - so you may use Rita to create generative text and still work with Max for other things.

Moreover Rita is also available in JavaScript version, as a library for P5js (http://p5js.org) - JavaScript Processing incarnation. Because P5js is operating on HTML/JavaScript/CSS code (in other words: it is producing a webpages which you can load into any web browser) you can code main mechanisms for text analysis and synthesis inside P5js "sketch" and to load this sketch inside Max into [jweb] object. Bidirectional communication between a "webpage" loaded inside [jweb] and Max is relatively simple to establish and handle.

Some time ago I prepared simple solution illustrating, how to integrate P5js sketches with Max. It is available here:

linlin's icon

Thanks a lot for your answer, many useful directions there !
I was thinking to go the java route too, and your integration exemple of p5js in max made me gain a lot of time.

I was wondering now what about text to speech (tts) engines.
Probably Java is the way to go too.
Beyond FreeTTS, i found MARY (http://mary.dfki.de/) which seems to be really interesting.
If you have any other suggestion, i would be really interested.

yaniki's icon

Chromium browser currently doesn’t support the Web Speech API - so you can't do that via [jweb].

Java-based solutions which you proposed should work, but personally I prefer method described here:

It works for OSX (remember, you have to install [shell] external first: https://cycling74.com/tools/bernstein-shell/#.WFQ0Q7GZO_M) and here you may find some tricks for similar solution on Windows:

yaniki's icon

PS. oh, I see that [shell] object is now a part of the Samplor package, so you can use Max Package Manager instead of link I provided.

linlin's icon

Yes, the only problem is that on windows environnements, the native TTS possibilities are not at all the same quality than the 'say' command on mac OS..

I like the idea of the shell object though, so now i will need to find a (better if) opensource, shell accessible, tts engine, compatible with windows.

yaniki's icon

Hmmm... I forgot, how ugly this Windows build-in speech synthesis is... maybe you may check the Web Speech API with browsers under Windows and if you find a voice with good quality just connect it to Max via WebSocket?

yaniki's icon

Maybe this will interest people reading this thread:

I updated "MaxAndP5js" - my collection of Max and P5js integration examples. I added a new example, a text generator based on RiTa library (https://rednoise.org/rita) for p5js.