Coder Social home page Coder Social logo

activenick / unity-text-to-speech Goto Github PK

View Code? Open in Web Editor NEW
96.0 7.0 25.0 13.25 MB

Sample app used to demonstrate the use of Microsoft Cognitive Services Text-to-Speech APIs (aka Speech Synthesis) from within Unity.

License: MIT License

C# 100.00%
speech-api cognitive-services unity voice uwp speechmanager microsoft azure

unity-text-to-speech's Introduction

Unity-Text-to-Speech

Sample app used to demonstrate the use of Microsoft Cognitive Services Speech Service Text-to-Speech (TTS) APIs from within the Unity game engine. These cloud-based APIs provide access to higher quality voices, providing consistency across all client platforms. Check out the Text-to-Speech Overview page to try out & hear a sample of these voices.

This sample provides a self-contained SpeechManager component that is easy to reuse in your own Unity projects. Given that Cognitive Services are cloud APIs, they are therefore not available when offline. It is recommended to fallback on local platform-specific Text-to-Speech APIs when offline.

The code in this sample demonstrates two ways to call the Speech Synthesis service. The first makes use of the Text-to-Speech REST API endpoint. When running the sample, make sure the checkbox "Use SDK Plugin" is unchecked to use this method. The second approach uses the new Cognitive Services Speech SDK for Unity, which features a plugin for Windows Desktop, UWP and Android, available as part of of a Unity package. IMPORTANT: The plugin is not included with this repo and you must import it in your project or the sample won't run. You can download the Unity package from here.

  • Unity version: 2018.3.14f1
  • Target platforms tested (REST API): Unity Editor, Windows Desktop (standalone x64), UWP, Android, iOS
  • Target platforms tested (Plugin): Unity Editor

Implementation Notes

  • THE CODE IN THIS SAMPLE APP ONLY WORKS WITH THE .NET 4.6 SCRIPTING RUNTIME. Additionally, there seems to be an issue with the use of HttpClient in Unity 2018.1.
  • This sample requires a Microsoft Cognitive Services Speech API key. FOR MORE INFO ON AUTHENTICATION AND HOW TO GET YOUR API KEY, PLEASE VISIT THIS PAGE. Don't use the key in this sample app, it's mine and I reserve the right to invalidate it if/when I want, use this link and go get your own. The free tier gives you 5,000 free API transactions / month.
  • The CustomCertificatePolicy class in SpeechManager.cs is required to circumvent a TLS bug in Unity 2018.1, otherwise Unity will throw an error stating the certificate is invalid. This temporary workaround simply bypasses certificate validation. This has been fixed in Unity 2018.2+ and will be removed after more testing is done. Note that UWP doesn't have this bug, only Mono, hence the conditional code.
  • TTSClient.cs contains a VoiceName enum with all the voices currently implemented in this sample. This may not include all the voices supported by the Cognitive Services Text-to-Speech API. Please visit this page to get the most up-to-date list of supported languages. Don't forget to edit ConvertVoiceNametoString() if you add more values to this enum to use more supported languages.
  • To change the pitch of the voice playback, use a delta value in Hz. Default is 0 (zero). Typical accepted delta changes can range from -10 to 10. Note: This currently only works with the REST API.

Follow Me

unity-text-to-speech's People

Contributors

activenick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

unity-text-to-speech's Issues

Speech Access Token not Refreshing

In SpeechManager.cs, you're getting the initial access token from the server and using that for the runtime of the application. Even though the Authentication class is re-authenticating in the background, the new access token is never being used in SpeechManager.cs (only the first token recieved).

Cannot change voicenames to foreign types

I am using the documentation found on this page:
https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support

...To substitute the default "enUSJessaRUS" speech synethesis into one of the foreign "Standard Voices"(specifically "ja-JP-Ayumi") in the "Voicename voicename" variable field in the "Speech Recognition" 3 language translation scene inside the Unity C# "Speech Recognition" script.

To Reproduce

Steps to reproduce the behavior:

Load the Speech Recognition scene into Unity and enter the Azure cognitive service credentials.
Voicename should be assigned in the Start() section.
voiceName = VoiceName.enUSJessaRUS;
to
voiceName = VoiceName.VoiceName.ja-JP-Ayumi;
Throws error for change of voice in the compiler. Eliminating hyphens does not fix this.
Expected behavior-3 errors in console...

--Assets\Cogntive Services\speech\SpeechSDKSample\Scripts\SpeechRecognition.cs(132,34): error CS0103: The name 'JP' does not exist in the current context

--Assets\Cogntive Services\speech\SpeechSDKSample\Scripts\SpeechRecognition.cs(132,34): error CS0103: The name 'jp' does not exist in the current context

--Assets\Cogntive Services\speech\SpeechSDKSample\Scripts\SpeechRecognition.cs(132,34): error CS0103: The name 'Ayumi' does not exist in the current context

Version of the Cognitive Services Speech SDK
Which version of the SDK are you using.

All latest versions of cogservices and this project

Windows 10u x64 C# Unity 2020.3.4f

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.