-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
31 lines (27 loc) · 853 Bytes
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
lovr.speech = require 'lua-deepspeech'
function lovr.load()
lovr.speech.init({
model = lovr.filesystem.getSource() .. '/deepspeech-0.9.3-models.pbmm'
})
-- Decode a sound file if provided
if arg[1] then
local sound = lovr.data.newSound(arg[1])
local count = sound:getFrameCount()
local samples = sound:getBlob():getPointer()
local text = lovr.speech.decode(samples, count)
print(text)
lovr.event.quit()
return
end
-- Otherwise set up microphone capture and feed audio to a speech decoder stream
sink = lovr.data.newSound(4096, 'f32', 'mono', 16000)
lovr.audio.setDevice('capture', 'default', sink)
lovr.audio.start('capture')
stream = lovr.speech.newStream()
end
function lovr.update(dt)
if sink:getFrameCount() > 1024 then
stream:feed(sink:getFrames())
print(stream:decode())
end
end