This commit is contained in:
2023-11-28 11:38:59 +05:30
commit ce059d4bf6
2742 changed files with 618089 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 74a55658d47885d45adbb75603a9374f
folderAsset: yes
timeCreated: 1482170538
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,84 @@
#if UNITY_WEBGL && !UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace UnityEngine
{
public class Microphone
{
[DllImport("__Internal")]
public static extern void Init();
[DllImport("__Internal")]
public static extern void QueryAudioInput();
[DllImport("__Internal")]
private static extern int GetNumberOfMicrophones();
[DllImport("__Internal")]
private static extern string GetMicrophoneDeviceName(int index);
[DllImport("__Internal")]
private static extern float GetMicrophoneVolume(int index);
private static List<Action> _sActions = new List<Action>();
public static void Update()
{
for (int i = 0; i < _sActions.Count; ++i)
{
Action action = _sActions[i];
action.Invoke();
}
}
public static string[] devices
{
get
{
List<string> list = new List<string>();
int size = GetNumberOfMicrophones();
for (int index = 0; index < size; ++index)
{
string deviceName = GetMicrophoneDeviceName(index);
list.Add(deviceName);
}
return list.ToArray();
}
}
public static float[] volumes
{
get
{
List<float> list = new List<float>();
int size = GetNumberOfMicrophones();
for (int index = 0; index < size; ++index)
{
float volume = GetMicrophoneVolume(index);
list.Add(volume);
}
return list.ToArray();
}
}
public static bool IsRecording(string deviceName)
{
return false;
}
public static void GetDeviceCaps(string deviceName, out int minFreq, out int maxFreq)
{
minFreq = 0;
maxFreq = 0;
}
public static void End(string deviceName)
{
}
}
}
#endif

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dc8de8dbe3174d24aaf7352e9ff48966
timeCreated: 1482170647
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,154 @@
var MicrophonePlugin = {
buffer: undefined,
Init: function() {
console.log("Init:");
// START - used to read the volume
document.volume = 0;
var byteOffset = 0;
var length = 1024;
this.buffer = new ArrayBuffer(4 * length);
document.dataArray = new Float32Array(this.buffer, byteOffset, length);
// END - used to read the volume
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (navigator.getUserMedia) {
var constraints = {
audio: {
optional: [{
sourceId: "audioSource"
}]
}
};
navigator.getUserMedia(constraints, function(stream) {
console.log('navigator.getUserMedia successCallback: ', stream);
document.position = 0;
document.audioContext = new AudioContext();
document.tempSize = 1024;
document.tempArray = new Float32Array(document.tempSize)
document.analyser = document.audioContext.createAnalyser();
document.analyser.minDecibels = -90;
document.analyser.maxDecibels = -10;
document.analyser.smoothingTimeConstant = 0.85;
document.mediaRecorder = new MediaRecorder(stream);
document.source = document.audioContext.createMediaStreamSource(stream);
document.source.connect(document.analyser);
document.mediaRecorder.start();
console.log(document.mediaRecorder.state);
document.readDataOnInterval = function() {
if (document.dataArray == undefined) {
setTimeout(document.readDataOnInterval, 250); //wait to be set
return;
}
document.tempInterval = Math.floor(document.tempSize / document.dataArray.length * 250);
// read the next chunk after interval
setTimeout(document.readDataOnInterval, document.tempInterval); //if mic is still active
if (document.dataArray == undefined) {
return;
}
//read the temp data buffer
document.analyser.getFloatTimeDomainData(document.tempArray);
// use the amplitude to get volume
document.volume = 0;
var j = (document.position + document.dataArray.length - document.tempSize) % document.dataArray.length;
for (var i = 0; i < document.tempSize; ++i) {
document.volume = Math.max(document.volume, Math.abs(document.tempArray[i]));
document.dataArray[j] = document.tempArray[i];
j = (j + 1) % document.dataArray.length;
}
document.position = (document.position + document.tempSize) % document.dataArray.length;
};
document.readDataOnInterval();
}, function(error) {
console.error('navigator.getUserMedia errorCallback: ', error);
});
}
},
QueryAudioInput: function() {
console.log("QueryAudioInput");
document.mMicrophones = [];
if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {
console.log("enumerateDevices() not supported.");
} else {
// List microphones
navigator.mediaDevices.enumerateDevices()
.then(function(devices) {
devices.forEach(function(device) {
console.log("QueryAudioInput: kind="+device.kind + " device=", device, " label=" + device.label);
if (device.kind === 'audioinput') {
document.mMicrophones.push(device.label);
}
});
})
.catch(function(err) {
console.error(err.name + ": " + err.message);
});
}
},
GetNumberOfMicrophones: function() {
console.log("GetNumberOfMicrophones");
var microphones = document.mMicrophones;
if (microphones == undefined) {
console.log("GetNumberOfMicrophones", 0);
return 0;
}
console.log("GetNumberOfMicrophones length="+microphones.length);
return microphones.length;
},
GetMicrophoneDeviceName: function(index) {
//console.log("GetMicrophoneDeviceName");
var returnStr = "Not Set";
var microphones = document.mMicrophones;
if (microphones != undefined) {
if (index >= 0 && index < microphones.length) {
if (microphones[index] != undefined) {
returnStr = microphones[index];
}
}
}
console.log("GetMicrophoneDeviceName", returnStr);
var buffer = _malloc(lengthBytesUTF8(returnStr) + 1);
writeStringToMemory(returnStr, buffer);
return buffer;
},
GetMicrophoneVolume: function(index) {
console.log("GetMicrophoneVolume");
if (document.volume == undefined) {
return 0;
}
console.log("GetMicrophoneVolume", document.volume);
return document.volume;
}
};
mergeInto(LibraryManager.library, MicrophonePlugin);

View File

@@ -0,0 +1,24 @@
fileFormatVersion: 2
guid: 896ade07724ca1c46ba94e7dc026f82e
timeCreated: 1482170554
licenseType: Pro
PluginImporter:
serializedVersion: 1
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
Any:
enabled: 0
settings: {}
Editor:
enabled: 0
settings:
DefaultValueInitialized: true
WebGL:
enabled: 1
settings: {}
userData:
assetBundleName:
assetBundleVariant: