9#if defined(_WIN32) || defined(WIN32)
41std::string
GetEnv(
const std::string& name)
43 char *data=getenv(name.c_str());
45 return std::string(data);
54 #if defined(_WIN32) || defined(WIN32)
56 _setmode(_fileno(stdin), _O_BINARY);
57 _setmode(_fileno(stdout), _O_BINARY);
65 std::cerr <<
"ProcessLoop: input stopped"<< std::endl;
69 if (stopthread)
break;
74 std::cerr <<
"Failed to write audio output" << std::endl;
83 std::cerr <<
"Usage: " << progname << std::endl;;
84 std::cerr <<
" Reads audio from stdin and return processed audio in stdout" << std::endl;
85 std::cerr <<
"Environment:"<< std::endl;;
86 std::cerr <<
" - S4STORE_PATH : path to store config [default: (no storage)]"<< std::endl;;
87 std::cerr <<
" - S4LOGINKEY : SOUND4 Login key (or S4USERID)"<< std::endl;;
88 std::cerr <<
" - RADIO_NAME : SOUND4 Radio Name"<< std::endl;;
89 std::cerr <<
" - ACCESS_KEY_ID : SOUND4 Access Key ID"<< std::endl;;
90 std::cerr <<
" - ACCESS_KEY_SECRET : SOUND4 Access Key Secret"<< std::endl;;
91 std::cerr << std::endl;
92 std::cerr <<
"Example:"<< std::endl;
94 #if defined(_WIN32) || defined(WIN32)
103 std::cerr << msg << std::endl;
106int main(
int argc,
const char **argv)
108#if (BIGVOICE_HAS_WEBSERVER)
109 int listen_port = 8080;
111 auto store_path_str=
GetEnv(
"S4STORE_PATH");
114 auto LoginKey=
GetEnv(
"S4LOGINKEY");
115 if (LoginKey.empty()) {
116 LoginKey=
GetEnv(
"S4USERID");
118 auto RadioName=
GetEnv(
"RADIO_NAME");
119 auto KeyId=
GetEnv(
"ACCESS_KEY_ID");
120 auto AccessKey=
GetEnv(
"ACCESS_KEY_SECRET");
122 const char *progname=argv[0];
125 if ((strcasecmp(argv[1],
"-h")==0) || (strcasecmp(argv[1],
"--help")==0)) {
130 if (LoginKey.empty() || RadioName.empty() || KeyId.empty() || AccessKey.empty()) {
131 std::cerr <<
"Missing credentials in environment" << std::endl;
135 std::filesystem::path store_path;
136 if (!store_path_str.empty()) {
138 store_path = std::filesystem::path(store_path_str);
139 if (!std::filesystem::exists(store_path,ec) || !std::filesystem::is_directory(store_path,ec)) {
140 std::cerr <<
"Storage folder '"<<store_path.c_str()<<
"' is not a valid directory" << std::endl;
151 instance.
SetParam(
"ADMIN_USER",
"admin");
152 instance.
SetParam(
"ADMIN_SECRET",
"admin");
155 std::cerr <<
"Creating" << std::endl;
157 if (!instance.
Create(LoginKey, RadioName, KeyId, AccessKey, store_path)) {
158 std::cerr <<
"Failed to create the processing instance" << std::endl;
163#if (BIGVOICE_HAS_WEBSERVER)
164 std::cerr <<
"Starting web server" << std::endl;
167 std::cerr <<
"Failed to create the web server on port " << listen_port << std::endl;
176 auto answer = client->ProcessJson(R
"JSON({"get":{"processorname":null}})JSON");
177 std::cerr << "Request for processor name returned "<<answer<<std::endl;
183 std::cerr <<
"Stopping now" << std::endl;
186 std::cerr <<
"End" << std::endl;
std::array< float, OutputSampleSize > & GetBufferOut()
bool StartWebServer(int http_port, int https_port=0)
bool Create(const std::string &LoginKey, const std::string &RadioName, const std::string &Access_Key_ID, const std::string &Access_Key_Secret, const std::filesystem::path &save_path, int json_port=0, unsigned int frames_per_chunk=12)
std::array< float, InputSampleSize > & GetBufferIn()
std::shared_ptr< CClient > NewClient()
void SetParam(const std::string &name, const std::string &value)
static void SetLogSeverity(LogSeverity severity)
const size_t OutputSampleSize
static unsigned int GetSampleRate()
const size_t InputSampleSize
static unsigned int GetChannelCount()
static void SetLoggerCallback(log_cb_t cb)
int main(int argc, const char **argv)
void MyLogger(sound4::bigvoice::LogSeverity severity, const std::string &msg)
std::string GetEnv(const std::string &name)
void ProcessLoop(sound4::bigvoice::CInstance &instance)
void Usage(const char *progname)