tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
81.88k stars 2.46k forks source link

[bug] there is an error when using SpeechRecognition #6208

Open ayangweb opened 1 year ago

ayangweb commented 1 year ago

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

FabianLars commented 1 year ago

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.

alimehasin commented 1 year ago

@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>
FabianLars commented 1 year ago

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

alimehasin commented 1 year ago

@FabianLars, The issue happened on macOS v13.3

FabianLars commented 1 year ago

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

ayangweb commented 1 year ago

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

t880216t commented 1 year ago

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

ayangweb commented 1 year ago

webkitSpeechRecognition

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

Monkatraz commented 3 months ago

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.

timothyjoh commented 2 weeks ago

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.