名称“麦克风”在当前上下文中不存在。在window 8中打开unity(版本5.6.0f3)项目时遇到此错误。
RequireComponent (typeof (AudioSource))公共类SingleMicrophoneCapture : MonoBehaviour {
//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> ();
}
}如何解决这个问题。
发布于 2018-05-03 19:39:28
您收到此错误是因为您使用的平台不支持Microphone应用编程接口。WebGL是不支持Microphone应用编程接口的平台之一。除了WebGL之外,可能还有其他平台没有麦克风支持。
从构建设置切换到支持Microphone应用编程接口的平台。
你也可以使用Unity的preprocessor directives来保护它,并确保在使用不支持它的平台或没有实现它的平台时,Microphone API是而不是。
#if !UNITY_WEBGL
//YOUR Microphone CODE HERE
#endif如果你真的需要WebGL的麦克风,可以制作一个插件或者使用this one(不免费)。
发布于 2018-05-03 16:52:03
我们看不到您的using语句。
但看起来你好像不见了
using UnityEngine.AudioModule;https://stackoverflow.com/questions/50149356
复制相似问题