Commit 2daa1c53 authored by Dan Wilcox's avatar Dan Wilcox
Browse files

added demo1, updated readme and changelog

parent 55a14774
0.2.0: TBA
0.2.0: 2021 Jun 23
* added OSC sending
* added on screen recording status indicator
* added newer attrnn default model
* added demo1
* added changelog
* renamed project to "Language Identifier"
* source file format improvements and renaming
* source file format improvements and reorganization
* ignore generated xcode project files
......
......@@ -24,6 +24,12 @@ Dependencies
- [ofxTensorFlow2](https://github.com/zkmkarlsruhe/ofxTensorFlow2)
* Pre-trained language id model(s) placed in `bin/data` (included in this repo)
Tested Platforms
----------------
* MacBook Pro 2017, macOS 10.15 & openFrameworks 0.11.2
* MacBook Pro 2018, macOS 11.3.1 & openFrameworks 0.11.2
Structure
---------
......@@ -92,11 +98,21 @@ Message specification:
- name: string, language map name
- confidence: float, confidence percentage 0 - 100
Tested Platforms
----------------
Demos
-----
* MacBook Pro 2017, macOS 10.15 & openFrameworks 0.11.2
* MacBook Pro 2018, macOS 11.3.1 & openFrameworks 0.11.2
The demos consist of rapid prototypes built using the following components:
* language identifier
* visual front end: [loaf](http://danomatika.com/code/loaf)
Custom visual front ends are written in Lua for [loaf](http://danomatika.com/code/loaf), a Lua interpreter with bindings for [openFrameworks](http://openframeworks.cc/) which includes a built-in Open Sound Control (OSC) server.
### Usage
To set up a run environment on macOS, download oaf and place the .app in the system `/Applications` folder.
To run a loaf project, drag the main Lua script or project folder onto the loaf.app.
The Intelligent Museum
----------------------
......
Demo 1
======
Copyright (c) 2021 Dan Wilcox.
Show greeting for one of the detected languages.
Usage
-----
1. start language identifier
2. run `main.lua` in loaf, ie. drag and drop script onto loaf.app
3. speak
The recording status is shown on screen to the lower right.
Key commands:
* 1-5: show greeting(s) manually
* d: toggle debug view
OSC Communication
-----------------
```
identifier --OSC--> main.lua
```
identifier:
* send address: "localhost"
* send port: 9999
main.lua
* receive port: 9999
-- Hello Demo
-- Copyright (c) 2021 Dan Wilcox
----- data -----
local lang = {
{name = "noise", locale = "xx"},
{name = "english", locale = "en"},
{name = "french", locale = "fr"},
{name = "german", locale = "de"},
{name = "spanish", locale = "es"}
}
local greeting = {
xx = "...",
en = "Hello",
de = "Guten Tag",
fr = "Bonjour",
es = "Hola"
}
----- text -----
local text = {
text = "",
animating = false,
speed = 100,
char = 0,
timestamp = 0,
font = of.TrueTypeFont(),
setup = function(self)
self.font:load(of.TTF_MONO, 64)
end,
set = function(self, s)
self.text = s
self.char = 0
self.timestamp = of.getElapsedTimeMillis()
self.animating = true
end,
update = function(self)
if self.animating then
if of.getElapsedTimeMillis() - self.timestamp > self.speed then
self.char = self.char + 1
if self.char >= #self.text then
self.char = #self.text
self.animating = false
else
self.timestamp = of.getElapsedTimeMillis()
end
end
end
end,
draw = function(self, ddebug)
local spacing = 4
local charw = self.font:stringWidth("#")
local wordw = (charw + spacing) * self.char
local lineh = self.font:getLineHeight()
local x = 0
of.pushMatrix()
of.translate((of.getWidth() / 2) - wordw / 2,
(of.getHeight() / 2) - lineh)
if ddebug then
of.noFill()
of.setColor(200, 100, 200)
of.drawRectangle(0, 0, wordw, lineh)
end
of.setColor(64)
for i=1,self.char do
self.font:drawString(self.text:sub(i, i), x, lineh)
x = x + charw + spacing
end
of.popMatrix()
end
}
----- thinking -----
local thinking = {
text = "?",
animating = false,
onoff = false,
speed = 500,
timestamp = 0,
font = of.TrueTypeFont(),
setup = function(self)
self.font:load(of.TTF_MONO, 48)
end,
show = function(self)
self.timestamp = of.getElapsedTimeMillis()
self.animating = true
self.onoff = true
end,
hide = function(self)
self.animating = false
end,
update = function(self)
if self.animating then
if of.getElapsedTimeMillis() - self.timestamp > self.speed then
self.onoff = not self.onoff
self.timestamp = of.getElapsedTimeMillis()
end
end
end,
draw = function(self)
if self.onoff then
local wordw = self.font:stringWidth(self.text)
local lineh = self.font:getLineHeight()
of.setColor(100, 200, 100)
self.font:drawString(self.text, of.getWidth() - (wordw + 4),
of.getHeight() - 4)
end
end
}
----- main -----
local plang = nil
local detecting = false
local confidence = 0
local ddebug = false
function setup()
of.background(255)
text:setup()
thinking:setup()
loaf.setListenPort(9999)
loaf.startListening()
end
function update()
text:update()
thinking:update()
end
function draw()
text:draw(ddebug)
thinking:draw()
if ddebug then
if plang then
of.setColor(100)
of.drawBitmapString(plang.locale.." "..string.format(" %.2f%%", confidence), 6, 12)
end
if detecting then
of.setColor(100)
of.drawBitmapString("detecting", of.getWidth() - 78, 12)
end
end
end
function keyPressed(key)
if key >= 49 and key <= 53 then
local l = lang[key - 48]
if l ~= plang then
text:set(greeting[l.locale])
end
plang = l
elseif key == string.byte("d") then
ddebug = not ddebug
end
end
function oscReceived(message)
--print(message)
if message:getAddress() == "/detecting" then
detecting = message:getArgAsBool(0)
if detecting then
thinking:show()
else
thinking:hide()
end
elseif message:getAddress() == "/lang" then
local index = message:getArgAsInt(0) + 1
confidence = message:getArgAsFloat(2)
local l = lang[index]
if l then
if l ~= plang then
text:set(greeting[l.locale])
end
plang = l
else
print("unknown lang: "..tostring(message))
end
end
end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment