mirror of
https://github.com/jambonz/freeswitch-modules.git
synced 2025-12-19 09:07:44 +00:00
@@ -26,6 +26,21 @@ typedef boost::circular_buffer<uint16_t> CircularBuffer_t;
|
||||
|
||||
static std::string fullDirPath;
|
||||
|
||||
static std::shared_ptr<grpc::Channel> create_grpc_channel(switch_channel_t *channel) {
|
||||
const char* google_uri = "texttospeech.googleapis.com";
|
||||
const char* var;
|
||||
if (var = switch_channel_get_variable(channel, "GOOGLE_TTS_APPLICATION_CREDENTIALS")) {
|
||||
auto channelCreds = grpc::SslCredentials(grpc::SslCredentialsOptions());
|
||||
auto callCreds = grpc::ServiceAccountJWTAccessCredentials(var);
|
||||
auto creds = grpc::CompositeChannelCredentials(channelCreds, callCreds);
|
||||
return grpc::CreateChannel(google_uri, creds);
|
||||
}
|
||||
else {
|
||||
auto creds = grpc::GoogleDefaultCredentials();
|
||||
return grpc::CreateChannel(google_uri, creds);
|
||||
}
|
||||
}
|
||||
|
||||
static void start_synthesis(const char* text, google_t* g) {
|
||||
try {
|
||||
SynthesizeSpeechRequest request;
|
||||
@@ -35,10 +50,11 @@ static void start_synthesis(const char* text, google_t* g) {
|
||||
auto voice = request.mutable_voice();
|
||||
auto custom_voice = voice->mutable_custom_voice();
|
||||
auto audio_config = request.mutable_audio_config();
|
||||
auto channelCreds = grpc::SslCredentials(grpc::SslCredentialsOptions());
|
||||
auto callCreds = grpc::ServiceAccountJWTAccessCredentials(g->credential);
|
||||
auto creds = grpc::CompositeChannelCredentials(channelCreds, callCreds);
|
||||
auto channel = grpc::CreateChannel("texttospeech.googleapis.com", creds);
|
||||
/* lock and unlock session */
|
||||
switch_core_session_t *psession = switch_core_session_locate(g->session_id);
|
||||
switch_channel_t *swChannel = switch_core_session_get_channel(psession);
|
||||
switch_core_session_rwunlock(psession);
|
||||
auto channel = create_grpc_channel(swChannel);
|
||||
auto stub = TextToSpeech::NewStub(channel);
|
||||
|
||||
if (strstr(text, "<speak") == text) {
|
||||
@@ -223,11 +239,6 @@ extern "C" {
|
||||
}
|
||||
}
|
||||
|
||||
if (!g->credential) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "google_speech_feed_tts: no credential provided\n");
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
if (!g->language) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "google_speech_feed_tts: no language provided\n");
|
||||
return SWITCH_STATUS_FALSE;
|
||||
|
||||
@@ -9,7 +9,6 @@ static void clearGoogle(google_t* g, int freeAll) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "clearGoogle\n");
|
||||
|
||||
if (g->cache_filename) free(g->cache_filename);
|
||||
if (g->credential) free(g->credential);
|
||||
if (g->model) free(g->model);
|
||||
if (g->reported_usage) free(g->reported_usage);
|
||||
if (g->gender) free(g->gender);
|
||||
@@ -17,7 +16,6 @@ static void clearGoogle(google_t* g, int freeAll) {
|
||||
if (g->err_msg) free(g->err_msg);
|
||||
|
||||
g->cache_filename = NULL;
|
||||
g->credential = NULL;
|
||||
g->model = NULL;
|
||||
g->reported_usage = NULL;
|
||||
g->gender = NULL;
|
||||
@@ -105,10 +103,7 @@ static void g_text_param_tts(switch_speech_handle_t *sh, char *param, const char
|
||||
{
|
||||
google_t *g = createOrRetrievePrivateData(sh);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "g_text_param_tts: %s=%s\n", param, val);
|
||||
if (0 == strcmp(param, "credential")) {
|
||||
if (g->credential) free(g->credential);
|
||||
g->credential = strdup(val);
|
||||
} else if (0 == strcmp(param, "voice")) {
|
||||
if (0 == strcmp(param, "voice")) {
|
||||
if (g->voice_name) free(g->voice_name);
|
||||
g->voice_name = strdup(val);
|
||||
} else if (0 == strcmp(param, "model")) {
|
||||
|
||||
@@ -10,7 +10,6 @@ typedef struct google_data {
|
||||
char *reported_usage;
|
||||
char *language;
|
||||
char *gender;
|
||||
char *credential;
|
||||
|
||||
/* result data */
|
||||
long response_code;
|
||||
|
||||
Reference in New Issue
Block a user