首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >名称“Microphone”在当前上下文单元中不存在

名称“Microphone”在当前上下文单元中不存在
EN

Stack Overflow用户
提问于 2018-05-03 15:33:33
回答 2查看 2K关注 0票数 2

名称“麦克风”在当前上下文中不存在。在window 8中打开unity(版本5.6.0f3)项目时遇到此错误。

RequireComponent (typeof (AudioSource))公共类SingleMicrophoneCapture : MonoBehaviour {

代码语言:javascript
复制
    //A boolean that flags whether there's a connected microphone
    private bool micConnected = false;

    //The maximum and minimum available recording frequencies
    private int minFreq;
    private int maxFreq;

    //A handle to the attached AudioSource
    public AudioSource goAudioSource;
    public AudioClip recordedAudioClip;
    [HideInInspector]
    public AudioClip myAudioClip;
    //public Text fileExist;
    bool startRecording = false;

    public Sprite[] recordingSprites;
    public int count =0;
    //int recordedFileCount =0;
    public bool isDefaultAudioPlaying = false;
    [SerializeField]
    public Sprite[] playSprites;
    public GameObject forwardButton;
    public GameObject backwardButton;
    public GameObject playButton;
    public GameObject replayButton;
    //Use this for initialization
    public AudioClip[] allAudioClips;
    public string storyName;
    float[] samples;
    public Dictionary<int,float> recordedClipDict;
    void Start() 
    {
            //ReplayButtonClicked ();
        //Check if there is at least one microphone connected

        recordedAudioClip= null;
        if(Microphone.devices.Length <= 0)

            {
            //Throw a warning message at the console if there isn't
            Debug.LogWarning("Microphone not connected!");
        }
        else //At least one microphone is present
        {
            //Set 'micConnected' to true
            micConnected = true;

            //Get the default microphone recording capabilities
            Microphone.GetDeviceCaps(null, out minFreq, out maxFreq);

            //According to the documentation, if minFreq and maxFreq are zero, the microphone supports any frequency...
            if(minFreq == 0 && maxFreq == 0)
            {
                //...meaning 44100 Hz can be used as the recording sampling rate
                maxFreq = 44100;
            }

            //Get the attached AudioSource component
            goAudioSource = this.GetComponent<AudioSource>();
          // mainAudioSource = Camera.main.GetComponent<AudioSource> ();
        }

    }

如何解决这个问题。

EN

回答 2

Stack Overflow用户

发布于 2018-05-03 19:39:28

您收到此错误是因为您使用的平台不支持Microphone应用编程接口。WebGL是不支持Microphone应用编程接口的平台之一。除了WebGL之外,可能还有其他平台没有麦克风支持。

从构建设置切换到支持Microphone应用编程接口的平台。

你也可以使用Unity的preprocessor directives来保护它,并确保在使用不支持它的平台或没有实现它的平台时,Microphone API是而不是

代码语言:javascript
复制
#if !UNITY_WEBGL
//YOUR Microphone CODE HERE
#endif

如果你真的需要WebGL的麦克风,可以制作一个插件或者使用this one(不免费)。

票数 4
EN

Stack Overflow用户

发布于 2018-05-03 16:52:03

我们看不到您的using语句。

但看起来你好像不见了

代码语言:javascript
复制
using UnityEngine.AudioModule;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50149356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档