In this Hello, World example, we will create a simple wordscript, and then generate a various types of media from it.
Requirements
You will need to install wordscript
from NPM
. You will also need to have vite-node
(or equivalent) installed to execute a Typescript
file.
Create the project and install dependencies
mkdir hello-word
cd hello-world
yarn init -y
yarn add wordscript
yarn add -D vite-node
Create the dialogue
hello-world.ws
Hello, World!
Generate the media
We will be creating the following media types:
- Slides with audio
- Slides without audio
- Audio only
- Website
- Video with audio
- Video without audio
hello-world.ts
import {runtime} from 'wordscript'
await runtime.load('hello-world.ws')
const targets = ['website', 'slides', 'slides+audio', 'audio', 'video', 'video+audio']
for (let target of targets ) {
runtime.generate(target).then(package => runtime.deploy(package, 'file'))
}
Run the build script
>> vite-node hello-world
You will now have a new directory call deploy
containing your packaged media.
hello-world
hello-world.ws
hello-world.ts
deploy
hello-world_website
hello-world_slides
hello-world_slides_av
hello-world_audio
hello-world_video
hello-world_av
Edit Dialogue
Let’s change our dialog by adding some expression elements to our Wordscript.
hello-world.ws
[[em Hello]], [[strong World]]!
[[pause 1000]]
That's all folks!
[[prompt close,restart]]
- The
em
andstrong
elements add the emphasis and strong expression.
When printed, they might result in italic and bold print, but when spoken they will result in stylistic inflections. - The
pause
element is a media instruction to wait for 1 second. - The prompt element adds an interactive instruction to either close the media, or replay it.
Run the build script again
>> vite-node hello-world
All media types have been rebuilt. Notice that elements behave differently depending on the media type.
Translate
We can also generate media for multiple languages.
Change the build script
hello-world.ts
import {runtime} from 'wordscript'
await runtime.load('hello-world.ws')
const targets = ['website', 'slides', 'slides+audio', 'audio', 'video', 'video+audio']
for (let target of targets ) {
runtime.generate(target, {language:['en', 'es', 'it']}).then(package => runtime.deploy(package, 'file'))
}
Run the build script
>> vite-node hello-world
You will now have a new directories in the deploy
directory; One for each language you specified.
hello-world
hello-world.ws
hello-world.ts
deploy
en
sp
it
...