dify icon indicating copy to clipboard operation
dify copied to clipboard

microphone not authorized

Open zps-509 opened this issue 2 years ago • 4 comments

Self Checks

  • [X] This is only for bug report, if you would like to ask a quesion, please head to Discussions.
  • [X] I have searched for existing issues search for existing issues, including closed ones.
  • [X] I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [X] Pleas do not modify this template :) and fill in all the required fields.

Dify version

0.6.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

image 默认语音模型已设置好 123 手机浏览器,怎么正确使用麦克风。

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

zps-509 avatar Apr 09 '24 02:04 zps-509

Hey there @zps-509! Good to see you back. Ran into a bit of a snag, huh? Let's see what we can do about that microphone mischief.

To resolve the "microphone not authorized" issue on a mobile device when using the "whisper-large-v3" and "tts-1" models in a self-hosted Dify application (version 0.6.0) running in Docker, you should ensure that your application is requesting microphone permissions from the user correctly. This involves handling the promise rejection when permissions are not granted and providing a user interface or guidance for users to manually enable microphone access in their browser settings.

In the Dify codebase, specifically in the web/app/components/app/chat/index.tsx file, the microphone permission is requested through the handleVoiceInputShow function. This function calls Recorder.getPermission(), which triggers the browser's permission request for microphone access. If the permission is granted, the state voiceInputShow is set to true, allowing the voice input feature to be used.

Here's the relevant code snippet:

const [voiceInputShow, setVoiceInputShow] = useState(false)
const handleVoiceInputShow = () => {
  (Recorder as any).getPermission().then(() => {
    setVoiceInputShow(true)
  }, () => {
    logError(t('common.voiceInput.notAllow'))
  })
}

When the promise from (Recorder as any).getPermission() is rejected, it indicates that the user has denied microphone access. You can catch this rejection to handle it more gracefully.

Here's an example modification to the handleVoiceInputShow function to include a more informative error handling:

const handleVoiceInputShow = () => {
  (Recorder as any).getPermission().then(() => {
    setVoiceInputShow(true)
  }, () => {
    // Log the error and inform the user more clearly about the need to enable microphone permissions.
    logError(t('common.voiceInput.notAllow'))
    // Optionally, show a modal or a notification with instructions on how to enable microphone access.
    notify({
      type: 'info',
      message: t('common.voiceInput.enableAccessInstructions'), // Make sure to add this key to your translation files
      duration: 5000
    })
  })
}

Ensure that you have a translation key common.voiceInput.enableAccessInstructions that provides a clear message or instructions to the user on how to enable microphone access in their browser settings.

Regarding the "whisper-large-v3" model for speech recognition and "tts-1" model for text-to-speech, these are integrated into the Dify application through a generic ModelManager class in the api/services/audio_service.py file. However, these integrations do not directly affect microphone permissions. Microphone permissions are typically handled at the application level (e.g., through the app's frontend or mobile app permissions) or the operating system level. The backend service processes audio files that have already been uploaded or sent to the server. Therefore, any integration of speech recognition or text-to-speech functionalities at the backend level would not directly affect microphone permissions. Microphone permissions would need to be managed where the audio capture functionality is implemented, likely in the client-side application that interacts with this backend service.

You can find more details in the source code:

I hope this helps! If you have any further questions, feel free to ask.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Apr 09 '24 02:04 dosubot[bot]

Please check the settings of the mobile phone.

crazywoola avatar Apr 09 '24 02:04 crazywoola

是不是非要https才能使用麦克风呀? 有没这个限制。

zps-509 avatar Apr 15 '24 02:04 zps-509

这个问题得怎么解决,按照上面的方法修改了也没有用。

1510386060 avatar May 16 '24 02:05 1510386060