Last active
June 9, 2024 10:11
-
-
Save lincerely/23033da55c120aa29cd5bdaa437200a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "voicevox_core/voicevox_core.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
int main(int argc, char** argv) | |
{ | |
if (argc < 3) { | |
fprintf(stderr, "%s SPEAKER_ID TEXT\n", argv[0]); | |
return 1; | |
} | |
char *end = NULL; | |
uint32_t sid = strtoul(argv[1], &end, 10); | |
int32_t res; | |
struct VoicevoxInitializeOptions initopts = { | |
VOICEVOX_ACCELERATION_MODE_GPU, | |
0, | |
false, | |
"voicevox_core/open_jtalk_dic_utf_8-1.11" | |
}; | |
res = voicevox_initialize(initopts); | |
if (res) { | |
fprintf(stderr, "failed to initialize: %s\n", voicevox_error_result_to_message(res)); | |
return 1; | |
} | |
res = voicevox_load_model(sid); | |
if (res) { | |
fprintf(stderr, "failed to load model: %s\n", voicevox_error_result_to_message(res)); | |
return 1; | |
} | |
struct VoicevoxTtsOptions ttsopts = voicevox_make_default_tts_options(); | |
uintptr_t len; | |
uint8_t *wav; | |
res = voicevox_tts(argv[2], sid, ttsopts, &len, &wav); | |
if (res) { | |
fprintf(stderr, "tts failed: %s\n", voicevox_error_result_to_message(res)); | |
return 1; | |
} | |
FILE *wavfile = fopen("output.wav", "wb"); | |
size_t olen = fwrite(wav, 8, len/8, wavfile); | |
fwrite(wav+(olen*8), 1, len-(olen*8), wavfile); | |
fclose(wavfile); | |
voicevox_wav_free(wav); | |
voicevox_finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment