【问题标题】:Pyinstaller app not getting microphone permission works fine with terminalPyinstaller 应用程序未获得麦克风权限适用于终端
【发布时间】:2021-09-15 13:20:58
【问题描述】:

我们的脚本使用以下库

import os
import sys
from random import sample as rand_sample
import PySimpleGUI as sg
from gtts import gTTS
from Levenshtein import ratio
from cryptography.fernet import Fernet
import platform
import webbrowser
from hashlib import sha1
from getpass import getuser
from socket import gethostname
import clipboard
import wavio
import sounddevice as sd
import soundfile as sf
import speech_recognition as sr
import wave
from playsound import playsound
from difflib import get_close_matches
import json
import urllib.request
from ssl import _create_unverified_context

class audio():
def __init__(mic,path):
    mic.fs=44100
    mic.path=path
def recordAudio(mic,time):
    recording=sd.rec(int(time*mic.fs),samplerate=mic.fs,channels=1)
    sd.wait()
    return recording
def save(mic,filename,recording):
    wavio.write(mic.path+filename,recording, mic.fs, sampwidth=2)
def play(mic,filename):
    data,fs = sf.read(mic.path+filename,dtype='float32')
    sd.play(data,fs)
    status=sd.wait()
def getText(mic,filename): #use google speech recongition to convert
    # print (mic,filename)
    r = sr.Recognizer()
    hellow=sr.AudioFile(mic.path+filename)
    with hellow as source:
        r.adjust_for_ambient_noise(source, duration = 1)

        audio = r.record(source)
    try:
        s = r.recognize_google(audio)
        return(s)
    except:
        return ('error reading speech...')
    return ""

通过终端运行应用程序包时可以访问麦克风(已授予权限)

但是,当我们使用 pyinstaller 使用此命令对其进行打包时

pyinstaller --noupx --onedir --onefile --windowed interview.spec interview.py

它已成功转换为应用程序,我们可以双击启动它。但它无法访问麦克风,也不会请求许可。我们是否必须添加一些特定的 python sn-p 来请求许可?期待您的建议和帮助,因为我对此一无所知。

系统: macOS 大苏尔 版本 11.5.2

【问题讨论】:

  • 访问麦克风的具体代码是什么?你能提供一个minimal reproducible example吗?
  • 感谢您的评论。我已经更新了我的问题
  • 尝试从终端运行捆绑包,它会显示错误日志并更新您的问题,这将更有帮助。
  • 谢谢我添加了更多信息,捆绑的应用程序在通过终端运行时可以正常工作

标签: python pyinstaller macos-big-sur


【解决方案1】:

最后只是写了一个脚本并在上面放了一个图标,所以用户可以双击它并开始使用该应用程序。尽管在 Big Sur 中,几乎每台复制到的新电脑都必须对其执行 chmod 755。

#!/bin/bash
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd "${DIR}"
./interview.app/Contents/MacOS/interview

【讨论】:

    猜你喜欢
    • 2019-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-19
    • 2021-06-11
    • 1970-01-01
    相关资源
    最近更新 更多