tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] there is an error when using SpeechRecognition

Open ayangweb opened this issue 2 years ago • 10 comments

Describe the bug

I'm using SpeechRecognition and I'm getting an error, the error is as shown in the picture, the code is fine in the browser but the error is reported in tauri, I guess it's a permission problem, should I get the audio permission? I hope you guys can give me some pointers!

iShot_2023-02-07_11 51 42

a simple code snippet is attached below

<script setup lang="ts">
const SpeechRecognition = window.webkitSpeechRecognition;

const recognition = new SpeechRecognition();
recognition.lang = 'cmn-Hans-CN';
recognition.continuous = true;

recognition.onresult = (e: any) => {
  console.log('e', e);
};
</script>

<template>
  <div>
    <button @click="recognition.start">开始</a-button>
    <button @click="recognition.stop">结束</a-button>
  </div>
</template>

Reproduction

No response

Expected behavior

No response

Platform and versions

Environment › OS: Mac OS 12.6.0 X64 › Node.js: 16.14.1 › npm: 8.19.3 › pnpm: 7.14.2 › yarn: 1.22.19 › rustup: 1.25.2 › rustc: 1.67.0 › cargo: 1.67.0 › Rust toolchain: stable-aarch64-apple-darwin

Packages › @tauri-apps/cli [NPM]: 1.2.3 › @tauri-apps/api [NPM]: 1.2.0 › tauri [RUST]: 1.2.4, › tauri-build [RUST]: 1.2.1, › tao [RUST]: 0.15.8, › wry [RUST]: 0.23.4,

Stack trace

No response

Additional context

No response

ayangweb avatar Feb 07 '23 03:02 ayangweb

Can you create a Info.plist file next to your tauri.conf.json file, similar to this: https://github.com/tauri-apps/tauri/blob/dev/examples/api/src-tauri/Info.plist with these contents

<key>NSMicrophoneUsageDescription</key>
<string>write some text describing the usage of the permission here</string>
<key>NSCameraUsageDescription</key>
<string>write some text describing the usage of the permission here</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>write some text describing the usage of the permission here</string>

Edit: Users on discord reported that this makes it work on macOS. Therefore i'm closing this issue.

FabianLars avatar Feb 20 '23 12:02 FabianLars

@FabianLars, I have tried this solution but the app crashes immediately without any log

The exact src-tauri/Info.plist content

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>NSMicrophoneUsageDescription</key>
  <string>write some text describing the usage of the permission here</string>
  <key>NSCameraUsageDescription</key>
  <string>write some text describing the usage of the permission here</string>
  <key>NSSpeechRecognitionUsageDescription</key>
  <string>write some text describing the usage of the permission here</string>
</dict>
</plist>

alimehasin avatar Apr 02 '23 11:04 alimehasin

@alimehasin Which macOS version are you using? I think it needs at least 11.3

FabianLars avatar Apr 03 '23 09:04 FabianLars

@FabianLars, The issue happened on macOS v13.3

alimehasin avatar Apr 03 '23 09:04 alimehasin

Alright i'll re-open this then until someone with a macos system can take a look.

FabianLars avatar Apr 03 '23 09:04 FabianLars

@FabianLars @alimehasin I'm sorry for my late reply,The problem has been solved, thanks!

ayangweb avatar Apr 04 '23 01:04 ayangweb

@ayangweb 兄弟,咋解决的啊。webkitSpeechRecognition调用了就崩溃哦

t880216t avatar Jun 28 '23 09:06 t880216t

webkitSpeechRecognition

mac 确实有这个问题,需要 debug 模式打包调试!

ayangweb avatar Jun 28 '23 10:06 ayangweb

I have this issue on MacOS, even after adding the NSSpeechRecognitionUsageDescription key - but only in development mode. If I do a full build, it works fine. This is on the 2.0 beta.

I can get crash reports and the report is simply that the NSSpeechRecognitionUsageDescription key is not found in the Info.plist. I guess it's something to do with the custom Info.plist not being exposed to MacOS while in development.

EDIT: I figured out the cause of my issue, and maybe this is relevant for tons of other strange issues with permissions that people are having. It turns out that if I do pnpm tauri dev through an integrated VSCode terminal (which I usually do) I will not be able to use speech recognition. If I do pnpm tauri dev just in a normal terminal, I don't get the issue.

Monkatraz avatar Jun 07 '24 20:06 Monkatraz

I get the problem when in development mode as well. whether I am in the terminal or not when I run bun run tauri dev. I seem to have trouble when it is built too, unlike the above comment.

Using the latest Tauri, 1.6 (not 2.0 rcs yet) and on Macbook M2 with Sonoma 14.5

When I added the Info.plist file, it DID ask me permission to use the microphone, but then it failed. When I start recognition, I can see the microphone icon on my menu bar flicker on and then immediately off.

Using the inspector, I am told "Siri and Dictation are diabled" Screenshot 2024-08-26 at 11 58 39 PM

This code seems to work fine in native Safari and Chrome on my Macbook.

timothyjoh avatar Aug 27 '24 03:08 timothyjoh

For me adding

  <key>NSSpeechRecognitionUsageDescription</key>
  <string> Write some text describing the usage of the permission here</string>

crashes the application, and if I don't add it, I get service-not-allowed error.

MacOS 15.0 (24A335)

ZeeshanAhmadKhalil avatar Oct 01 '24 11:10 ZeeshanAhmadKhalil

Can confirm working with src-tauri/Info.ios.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>NSMicrophoneUsageDescription</key>
  <string>write some text describing the usage of the permission here</string>
  <key>NSCameraUsageDescription</key>
  <string>write some text describing the usage of the permission here</string>
  <key>NSSpeechRecognitionUsageDescription</key>
  <string>write some text describing the usage of the permission here</string>
</dict>
</plist>

And running in dev mode from standalone mac terminal.

e-simpson avatar May 06 '25 11:05 e-simpson