Re: Trying to get Love2D game working under Windows, works fine on Linux
This is my speech code. Works on Linux and under Wine. If you can get it working under MacOS too, I'd appreciate the contribution. Note that this is the first Lua I've written in a decade or so, so make of it what you will.
-- The Windows portions of this code were adapted from the Pokecrystal Access scripts by Tyler Spivey.
-- Original scripts: https://github.com/tspivey/pokecrystal-access
local ffi = require("ffi") ffi.cdef[[ typedef enum { SPD_MODE_SINGLE = 0, SPD_MODE_THREADED = 1 } SPDConnectionMode; typedef enum { SPD_IMPORTANT = 1, SPD_MESSAGE = 2, SPD_TEXT = 3, SPD_NOTIFICATION = 4, SPD_PROGRESS = 5 } SPDPriority; void *spd_open(const char *client_name, const char *connection_name, const char *user_name, SPDConnectionMode mode); int spd_say(void *connection, SPDPriority priority, const char *text); int spd_cancel(void *connection); int spd_set_voice_rate(void *connection, signed int rate); void spd_close(void *connection); typedef unsigned int UINT; typedef unsigned int DWORD; typedef const char * LPCSTR; typedef wchar_t * LPWSTR; int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar); void Tolk_TrySAPI(bool trySAPI); void Tolk_Load(); bool Tolk_Output(const char *s, bool interrupt); void Tolk_Silence(); ]] local lib local kernel32 local speech if ffi.os == "Linux" then lib = ffi.load("speechd") speech = lib.spd_open("love2d", "love2d", "love2d", lib.SPD_MODE_SINGLE) lib.spd_set_voice_rate(speech, 100) elseif ffi.os == "Windows" then kernel32 = ffi.load("kernel32") lib = ffi.load("Tolk") lib.Tolk_TrySAPI(true) lib.Tolk_Load() end local CP_UTF8 = 65001 function to_utf16(s) local needed = kernel32.MultiByteToWideChar(CP_UTF8, 0, s, -1, NULL, 0) local buf = ffi.new("wchar_t[?]", needed) local written = kernel32.MultiByteToWideChar(CP_UTF8, 0, s, -1, buf, needed) return ffi.string(buf, written*2) end local M = {} function M.say(text, interrupt) if interrupt == nil then interrupt = true end if ffi.os == "Linux" then if interrupt then lib.spd_cancel(speech) end lib.spd_say(speech, lib.SPD_IMPORTANT, text) elseif ffi.os == "Windows" then lib.Tolk_Output(to_utf16(text), interrupt) end end function M.stop() if ffi.os == "Linux" then lib.spd_cancel(speech) elseif ffi.os == "Windows" then lib.Tolk_Silence() end end return M
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector