Is there a way to have change female to male voice

2020-02-10 08:14发布

问题:

We a building a chatbot app for Google Home using Api.ai (Dialogflow now) which has both male and female historical figures. We are using Actions on google. Google lets you default to a male or female voice when deploying the app. Is there a way to switch between male to female voice dynamically, for example, using code in webhook?

回答1:

Maybe. Although SSML supports a <voice> tag, the documentation for Actions does not list it as supported. However, as you noted, there appears to be some support. The gender and variant attributes seem to work, at least for en-US. The languages attribute doesn't seem to be. So something like this might work:

<speech>
    <voice gender="male" variant="1">male</voice>
    <voice gender="male" variant="2">male</voice>
    <voice gender="female" variant="1">female</voice>
    <voice gender="female" variant="2">female</voice>
</speech>

However what is documented as working is to adjust the pitch of the default voice (whichever one you pick) using the <prosody> SSML tag. Here is an example you can use to see how it sounds if you vary the pitch:

<speech>
    test
    <prosody pitch="-1st">test</prosody>
    <prosody pitch="-2st">test</prosody>
    <prosody pitch="-3st">test</prosody>
    <prosody pitch="-4st">test</prosody>
    <prosody pitch="-5st">test</prosody>
    <prosody pitch="-6st">test</prosody>
    <prosody pitch="-7st">test</prosody>
    <prosody pitch="-8st">test</prosody>
    <prosody pitch="-9st">test</prosody>
    <prosody pitch="+1st">test</prosody>
    <prosody pitch="+2st">test</prosody>
    <prosody pitch="+3st">test</prosody>
    <prosody pitch="+4st">test</prosody>
    <prosody pitch="+5st">test</prosody>
    <prosody pitch="+6st">test</prosody>
    <prosody pitch="+7st">test</prosody>
    <prosody pitch="+8st">test</prosody>
    <prosody pitch="+9st">test</prosody>
</speech>

You can also combine the two tags.