The “blob” in the tiddler’s text field does not contain the needed data:audio/mp3;base64,
URI prefix. Thus, transcluding just the text field would result in a malformed src
URI.
Also, here’s a small improvement on my previous response to allow any audio MIME type to be used:
<audio autoplay src=`data:${ [{MySound!!type}] }$;base64,${ [{MySound}] }$`/>
Note: Older versions of TiddlyWiki (before v5.3.0, released 1st July 2023), do not include support for the “backtick parameter parsing” syntax. To achieve the same results in those TiddlyWikis, you can use the following to construct the necessary URI:
<audio autoplay src={{{ [[data:]] [{MySound!!type}] [[;base64,]] [{MySound}] +[join[]] }}}/>
Lastly, for convenience you can create a global macro by creating a tiddler (e.g., “PlaySound”), tagged with $:/tags/Macro
, containing
\define playsound(tid)
<audio autoplay src={{{ [[data:]] [[$tid$]get[type]] [[;base64,]] [[$tid$]get[text]] +[join[]] }}}/>
\end
which you can then use in any tiddler content like this: <<playsound "tiddlername">>
Note that I have used the \define
and $param$
macro syntax, as well as the $:/tags/Macro
tag value. This ensures that the <<playsound>>
macro is 100% backward-compatible with older versions of TiddlyWiki.
enjoy,
-e