Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d Unity的麦克风没有播放任何声音_Unity3d - Fatal编程技术网

Unity3d Unity的麦克风没有播放任何声音

Unity3d Unity的麦克风没有播放任何声音,unity3d,Unity3d,我想让麦克风团结一致地工作。我没有收到任何错误,代码也没有中断,但是,我听不到麦克风的任何输出声音。我从连接到场景主摄像机的音频监听器获得的光谱数据没有改变 如果你们知道问题出在哪里,请告诉我: 这是我的密码: using System; using System.Collections; using System.Collections.Generic; using UnityEngine; ///<summary> /// Get the impulse response of

我想让麦克风团结一致地工作。我没有收到任何错误,代码也没有中断,但是,我听不到麦克风的任何输出声音。我从连接到场景主摄像机的音频监听器获得的光谱数据没有改变

如果你们知道问题出在哪里,请告诉我:

这是我的密码:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

///<summary>
/// Get the impulse response of a room with the device's microphone, to calculate the convolution reverb
///</summary>
[RequireComponent(typeof(AudioSource))]
public class ImpulseResponse : MonoBehaviour {
    private bool micFound = false;
    private AudioSource audioSource;

    private void Start() {
        audioSource = GetComponent<AudioSource>();
        // Ask for mic access from user before using it
        StartCoroutine(GetMicrophone());
    }

    private void StartRecording() {
        audioSource.clip = Microphone.Start(Microphone.devices[0], true, 10, AudioSettings.outputSampleRate);
        Debug.Log("Started recording");
        audioSource.loop = true;
        audioSource.Play();
    }

    private void StopRecording() {
        Debug.Log("Stop recording");
        Microphone.End(Microphone.devices[0]);
    }

    private IEnumerator GetMicrophone() {
        yield return Application.RequestUserAuthorization(UserAuthorization.Microphone);
        if (Application.HasUserAuthorization(UserAuthorization.Microphone)) {
            micFound = true;
            Debug.Log("Microphones found: ");
            foreach (var device in Microphone.devices) {
                Debug.Log("Name: " + device);
            }

            StartRecording();
        }
        else {
            Debug.Log("Microphone not found");
        }
    }

    private void Update() {
        // spectrum data --> https://docs.unity3d.com/ScriptReference/AudioSource.GetSpectrumData.html
        float[] spectrum = new float[256];
        AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.Rectangular);
        for (int i = 1; i < spectrum.Length - 1; i++) {
            Debug.DrawLine(new Vector3(i - 1, spectrum[i] + 10, 0), new Vector3(i, spectrum[i + 1] + 10, 0), Color.red);
            Debug.DrawLine(new Vector3(i - 1, Mathf.Log(spectrum[i - 1]) + 10, 2),
                new Vector3(i, Mathf.Log(spectrum[i]) + 10, 2), Color.cyan);
            Debug.DrawLine(new Vector3(Mathf.Log(i - 1), spectrum[i - 1] - 10, 1),
                new Vector3(Mathf.Log(i), spectrum[i] - 10, 1), Color.green);
            Debug.DrawLine(new Vector3(Mathf.Log(i - 1), Mathf.Log(spectrum[i - 1]), 3),
                new Vector3(Mathf.Log(i), Mathf.Log(spectrum[i]), 3), Color.blue);
        }
    }

原来UnityHub没有麦克风权限

以下是打开它的步骤:

在步骤10中,您将更改为:

重新启动Mac并按住Command-R,直到出现apple徽标和进度条。这将引导您的Mac进入恢复模式

您可能会看到一个窗口,要求您选择一种语言。如果是,请选择并单击箭头按钮继续

从菜单栏中选择实用程序/终端

在终端窗口中键入:csrutil disable…并点击return。您将看到一条消息,确认您已禁用系统完整性保护。我们将在完成之前重新启用此功能

从菜单栏中选择终端/退出终端

从菜单栏中选择Apple菜单/重新启动。出现提示时登录Mac

在Finder中,从菜单栏中选择Go/Utilities

双击实用程序文件夹中的“终端”

在终端中,小心地键入:sqlite3~/Library/Application\Support/com.apple.TCC/TCC.db …然后按回车键

在sqlite提示下,键入以下内容: 在访问值“ktccservicemicroscop”、“com.unity3d.unityhub”、0,1,1、NULL、NULL、NULL、‘未使用的’、NULL、01541440109中插入; …然后按回车键

在sqlite提示符下,键入以下内容:.exit…,然后单击return。一定要包括最初的时期

。否则退出命令将不起作用

从菜单栏中选择终端/退出终端

这将授予Ring应用程序使用您的麦克风的权限。现在我们需要重新启用系统完整性保护。重复步骤1-6,除了在步骤4中键入“启用”而不是“禁用”。这是一个重要的步骤,我强烈建议你不要跳过它

您可以通过选择Apple/System Preferences,然后选择Security&Privacy,然后单击Privacy(隐私)选项卡并选择窗口左侧的“麦克风”来确认此过程是否有效