diff --git a/examples/ggwave-to-file/README.md b/examples/ggwave-to-file/README.md index faf6d44..502bce7 100644 --- a/examples/ggwave-to-file/README.md +++ b/examples/ggwave-to-file/README.md @@ -3,10 +3,11 @@ Output a generated waveform to an uncompressed WAV file. ``` -Usage: ./bin/ggwave-to-file [-vN] [-sN] [-pN] +Usage: ./bin/ggwave-to-file [-vN] [-sN] [-pN] [-lN] -vN - output volume, N in (0, 100], (default: 50) -sN - output sample rate, N in [6000, 96000], (default: 48000) -pN - select the transmission protocol id (default: 1) + -lN - fixed payload length of size N, N in [1, 16] Available protocols: 0 - Normal @@ -40,6 +41,12 @@ Usage: ./bin/ggwave-to-file [-vN] [-sN] [-pN] echo "Hello world!" | ./bin/ggwave-to-file -p4 > example.wav ``` +- Use fixed-length encoding (i.e. no sound markers) + + ```bash + echo "Hello world!" | ./bin/ggwave-to-file -l12 > example.wav + ``` + ## HTTP service @@ -75,7 +82,7 @@ curl -sS 'https://ggwave-to-file.ggerganov.com/?m=Hello world!&p=4' --output hel ```python import requests -def ggwave(message: str, protocolId: int = 1, sampleRate: float = 48000, volume: int = 50): +def ggwave(message: str, protocolId: int = 1, sampleRate: float = 48000, volume: int = 50, payloadLength: int = -1): url = 'https://ggwave-to-file.ggerganov.com/' @@ -84,6 +91,7 @@ def ggwave(message: str, protocolId: int = 1, sampleRate: float = 48000, volume: 'p': protocolId, # transmission protocol to use 's': sampleRate, # output sample rate 'v': volume, # output volume + 'l': payloadLength, # if positive - use fixed-length encoding } response = requests.get(url, params=params) diff --git a/examples/ggwave-to-file/ggwave-to-file.php b/examples/ggwave-to-file/ggwave-to-file.php index a393d00..275d62a 100644 --- a/examples/ggwave-to-file/ggwave-to-file.php +++ b/examples/ggwave-to-file/ggwave-to-file.php @@ -5,6 +5,7 @@ $cmd = "ggwave-to-file"; if (isset($_GET['s'])) { $cmd .= " -s".intval($_GET['s']); } if (isset($_GET['v'])) { $cmd .= " -v".intval($_GET['v']); } if (isset($_GET['p'])) { $cmd .= " -p".intval($_GET['p']); } +if (isset($_GET['l'])) { $cmd .= " -l".intval($_GET['l']); } $descriptorspec = array( 0 => array("pipe", "r"), diff --git a/examples/ggwave-to-file/main.cpp b/examples/ggwave-to-file/main.cpp index 2cdfbaf..66d52d9 100644 --- a/examples/ggwave-to-file/main.cpp +++ b/examples/ggwave-to-file/main.cpp @@ -10,10 +10,11 @@ #include int main(int argc, char** argv) { - fprintf(stderr, "Usage: %s [-vN] [-sN] [-pN]\n", argv[0]); + fprintf(stderr, "Usage: %s [-vN] [-sN] [-pN] [-lN]\n", argv[0]); fprintf(stderr, " -vN - output volume, N in (0, 100], (default: 50)\n"); fprintf(stderr, " -sN - output sample rate, N in [%d, %d], (default: %d)\n", (int) GGWave::kSampleRateMin, (int) GGWave::kSampleRateMax, (int) GGWave::kBaseSampleRate); fprintf(stderr, " -pN - select the transmission protocol id (default: 1)\n"); + fprintf(stderr, " -lN - fixed payload length of size N, N in [1, %d]\n", GGWave::kMaxLengthFixed); fprintf(stderr, "\n"); fprintf(stderr, " Available protocols:\n"); @@ -36,6 +37,7 @@ int main(int argc, char** argv) { int volume = argm["v"].empty() ? 50 : std::stoi(argm["v"]); float sampleRateOut = argm["s"].empty() ? GGWave::kBaseSampleRate : std::stof(argm["s"]); int protocolId = argm["p"].empty() ? 1 : std::stoi(argm["p"]); + int payloadLength = argm["l"].empty() ? -1 : std::stoi(argm["l"]); if (volume <= 0 || volume > 100) { fprintf(stderr, "Invalid volume\n"); @@ -69,7 +71,7 @@ int main(int argc, char** argv) { fprintf(stderr, "Generating waveform for message '%s' ...\n", message.c_str()); - GGWave ggWave({ -1, GGWave::kBaseSampleRate, sampleRateOut, 1024, GGWave::kDefaultSamplesPerFrame, GGWAVE_SAMPLE_FORMAT_F32, GGWAVE_SAMPLE_FORMAT_I16 }); + GGWave ggWave({ payloadLength, GGWave::kBaseSampleRate, sampleRateOut, 1024, GGWave::kDefaultSamplesPerFrame, GGWAVE_SAMPLE_FORMAT_F32, GGWAVE_SAMPLE_FORMAT_I16 }); ggWave.init(message.size(), message.data(), ggWave.getTxProtocol(protocolId), volume); std::vector bufferPCM;