Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Oct 20, 2023
1 parent 483c454 commit 346ff05
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion components/app/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ GIT

GIT
remote: https://github.com/somleng/tts_voices.git
revision: 65a7b3024a27fb4c56dc03a86eb286fa1d83c24f
revision: 3d3f6b2d6fed77ea938a8628250fe0278d620fbe
specs:
tts_voices (0.1.0)
aws-sdk-polly
Expand Down
11 changes: 7 additions & 4 deletions components/app/app/models/execute_twiml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,20 @@ def resolve_tts_voice(attributes)
default_tts_voice = TTSVoices::Voice.find(call_properties.default_tts_voice)
voice_attribute = BASIC_TTS_MAPPING.fetch(voice_attribute) if BASIC_TTS_MAPPING.key?(voice_attribute)

if voice_attribute.blank? && language_attribute.present?
tts_voice = resolve_tts_voice_by_language(default_tts_voice.provider, language_attribute)
if voice_attribute.blank?
tts_voice = resolve_tts_voice_by_language(default_tts_voice, language_attribute)
voice_attribute = tts_voice&.identifier
end

TTSVoices::Voice.find(voice_attribute) || default_tts_voice
end

def resolve_tts_voice_by_language(provider, language_attribute)
def resolve_tts_voice_by_language(default_tts_voice, language_attribute)
return default_tts_voice if language_attribute.blank?
return default_tts_voice if default_tts_voice.language.casecmp(language_attribute).zero?

TTSVoices::Voice.all.find do |voice|
voice.provider == provider && voice.language.casecmp(language_attribute).zero?
voice.provider == default_tts_voice.provider && voice.language.casecmp(language_attribute).zero?
end
end
end
21 changes: 21 additions & 0 deletions components/app/spec/call_controllers/say_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@
expect(fetch_ssml_attribute(ssml, :lang)).to eq("nl-NL")
end
end

it "uses the default voice if the language is the same" do
controller = build_controller(
stub_voice_commands: :say,
call_properties: {
default_tts_voice: "Polly.Vitoria"
}
)
stub_twiml_request(controller, response: <<~TWIML)
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Say language="pt-BR">Hello World</Say>
</Response>
TWIML

controller.run

expect(controller).to have_received(:say) do |ssml|
expect(fetch_ssml_attribute(ssml, :name)).to eq("Polly.Vitoria")
end
end
end

describe "loop" do
Expand Down

0 comments on commit 346ff05

Please sign in to comment.