main.lua 853 B

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