Riley-Brown / react-speech-to-text

React Hooks for Speech to Text
MIT License
118 stars 31 forks source link

How to change SpeechRecognition lang #24

Closed dgastudio closed 3 years ago

dgastudio commented 3 years ago

Hey I have chrome in English, but I would like to define Spanish as well.

it's possible to change the language in cross-browser mode, but not in "native"

any advice? thanks

Riley-Brown commented 3 years ago

You could pass the googleCloudRecognitionConfig arg to the hook to specify the language code for cross-browser mode

 googleCloudRecognitionConfig: {
    languageCode: 'en-US'
  }

This language code will only apply for the browsers that don't support the native browser speech API

Read more here https://github.com/Riley-Brown/react-speech-to-text#googlecloudrecognitionconfig

dgastudio commented 3 years ago

Hello Riley!

Thank you for your response! But, i don't want to use google cloud. Instead, i want to set language in native mode as i can see, it's possible, https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/lang

how to apply this functionality in your plugin?

Riley-Brown commented 3 years ago

@dgastudio Yes it is also possible to specify the language for native chrome recognition with the speechRecognitionProperties

  speechRecognitionProperties: {
    lang: 'es',
  }

However, I would not recommend hardcoding a value here as the MDN docs state

If not specified, this defaults to the HTML lang attribute value, or the user agent's language setting

So this setting should be automatically set based on the user's browser language settings

dgastudio commented 3 years ago

awesome, thank you!

Logbook | HKeeper 🔊 2021-12-04 22-32-19