10#if __has_include(<filesystem>)
14 #include <experimental/filesystem>
16 namespace filesystem = experimental::filesystem;
19#if defined(_WIN32) || defined(WIN32)
22 #include <stringapiset.h>
26#define SAMPLE_RATE 48000
28#define CHANNEL_COUNT 2
38 #if defined(_WIN32) || defined(WIN32)
40 _setmode(_fileno(stdin), _O_BINARY);
41 _setmode(_fileno(stdout), _O_BINARY);
48 std::cerr <<
"ProcessLoop: input stopped"<< std::endl;
52 if (stopthread)
break;
57 std::cerr <<
"Failed to write audio output" << std::endl;
66 std::cerr <<
"Usage: " << progname << std::endl;;
67 std::cerr <<
" Reads audio from stdin and return processed audio in stdout" << std::endl;
68 std::cerr <<
"Environment:"<< std::endl;;
69 std::cerr <<
" - S4STORE_PATH : path to store config [default: ./state]"<< std::endl;;
70 std::cerr <<
" - S4LOGINKEY : SOUND4 Login key (or S4USERID)"<< std::endl;;
71 std::cerr <<
" - RADIO_NAME : SOUND4 Radio Name"<< std::endl;;
72 std::cerr <<
" - ACCESS_KEY_ID : SOUND4 Access Key ID"<< std::endl;;
73 std::cerr <<
" - ACCESS_KEY_SECRET : SOUND4 Access Key Secret"<< std::endl;;
74 std::cerr << std::endl;
75 std::cerr <<
"Example:"<< std::endl;
77 #if defined(_WIN32) || defined(WIN32)
86 std::cerr << str << std::endl;
90int main(
int argc,
char *
const argv[])
93 const char *store_path_str=getenv(
"S4STORE_PATH");
95 char *pLoginKey=getenv(
"S4LOGINKEY");
97 pLoginKey=getenv(
"S4USERID");
99 char *pRadioName=getenv(
"RADIO_NAME");
100 char *pKeyId=getenv(
"ACCESS_KEY_ID");
101 char *pAccessKey=getenv(
"ACCESS_KEY_SECRET");
103 const char *progname=argv[0];
106 if ((strcasecmp(argv[1],
"-h")==0) || (strcasecmp(argv[1],
"--help")==0)) {
111 if (!pLoginKey || !pRadioName || !pKeyId || !pAccessKey) {
112 std::cerr <<
"Missing credentials in environment" << std::endl;
117 std::filesystem::path fs_store_path;
118 if (!store_path_str || store_path_str[0]==0) {
119 fs_store_path=std::filesystem::current_path(ec) /
"state";
121 fs_store_path = std::filesystem::path(store_path_str);
123 if (!std::filesystem::exists(fs_store_path,ec) || !std::filesystem::is_directory(fs_store_path,ec)) {
124 std::cerr <<
"Storage folder '"<<fs_store_path.c_str()<<
"' is not a valid directory" << std::endl;
128 std::string store_path;
132 std::wstring wstr(fs_store_path.wstring());
133 if (wstr.empty())
return {};
134 int size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (
int)wstr.size(), NULL, 0, NULL, NULL);
135 std::string str(size, 0);
136 WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (
int)wstr.size(), &str[0], size, NULL, NULL);
140 store_path=fs_store_path;
178 std::cerr <<
"Failed to create the process instance"<< std::endl;
183 std::thread updater([pInstance](){
185 std::cerr <<
"bigvoice_StartUpdateThread (no json port)" << std::endl;
187 std::cerr <<
"bigvoice_StartUpdateThread END" << std::endl;
191 std::cerr <<
"Waiting update thread" << std::endl;
193 std::cerr <<
"Timeout to create the process instance"<< std::endl;
195 std::cerr <<
"Waiting update thread DONE" << std::endl;
197#if (BIGVOICE_HAS_WEBSERVER)
200 std::cerr <<
"Starting web server" << std::endl;
201 int listenport= 8080;
202 int listenport_secure= 8443;
204 if (listenport || listenport_secure) {
207 std::cerr <<
"Starting web server FAILED" << std::endl;
212 std::cerr <<
"Web server listening on port " << listenport;
214 std::cerr <<
"Web server failed to listen on port " << listenport;
217 if (listenport_secure) {
219 std::cerr <<
"Web server listening on secure port " << listenport_secure;
221 std::cerr <<
"Web server failed to listen on secure port " << listenport_secure;
224 std::cerr <<
"Starting web server DONE" << std::endl;
246#if (BIGVOICE_HAS_WEBSERVER)
248 std::cerr <<
"Stopping web server" << std::endl;
250 std::cerr <<
"Stopping web server DONE" << std::endl;
254 std::cerr <<
"Stopping Update thread" << std::endl;
256 std::cerr <<
"Stopping Update thread DONE" << std::endl;
void bigvoice_ProcessAudio(struct bigvoice_CInstance *instance, const float *input, float *output)
unsigned int bigvoice_GetEstimatedDelay(struct bigvoice_CInstance *instance)
unsigned int bigvoice_GetChannelCount()
void bigvoice_SetLogSeverity(enum bigvoice_LogSeverity severity)
unsigned int bigvoice_GetChunkSizeInFrames()
const char * bigvoice_GetVersion()
unsigned int bigvoice_GetSampleRate()
void bigvoice_FreeParameters(struct bigvoice_CParameters *params)
void bigvoice_ExitProcess(struct bigvoice_CInstance *instance)
struct bigvoice_CParameters * bigvoice_NewParameters()
struct bigvoice_CInstance * bigvoice_InitProcess2(const char *LoginKey, const char *RadioName, const char *Access_Key_ID, const char *Access_Key_Secret, const char *save_path, const struct bigvoice_CParameters *parameters)
void bigvoice_SetParameter(struct bigvoice_CParameters *params, const char *name, const char *value)
void bigvoice_StopUpdateThread(struct bigvoice_CInstance *instance)
int bigvoice_WaitUpdateThreadReady(struct bigvoice_CInstance *instance, int milliseconds)
void bigvoice_StartUpdateThread(struct bigvoice_CInstance *instance, unsigned int port)
#define SOUND4_WEBSERVER_HTTPS_OK
uint64_t bigvoice_Webserver(unsigned int listenport, unsigned int listenport_secure, struct bigvoice_CInstance *instance)
int bigvoice_Webserver_Stop(uint64_t id, int timeout_ms)
int bigvoice_Webserver_Status(uint64_t id)
#define SOUND4_WEBSERVER_HTTP_OK
#define SOUND4_INVALID_WEBSERVER_ID
void ProcessLoop(struct bigvoice_CInstance *pInstance)
void Usage(const char *progname)
int main(int argc, char *const argv[])
void MyLogger(bigvoice_LogSeverity severe, const char *str)