diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity index 35412be..7a91b37 100644 --- a/Assets/Scenes/Main.unity +++ b/Assets/Scenes/Main.unity @@ -493,7 +493,7 @@ MonoBehaviour: _maxAlternatives: 0 _autoLoadModel: 0 _autoStart: 0 - _audioChunkSize: 4096 + _audioChunkSize: 1024 _sampleRate: 16000 _audioClipBufferSeconds: 1 _listeningDevice: @@ -502,6 +502,7 @@ MonoBehaviour: _logPartialResults: 0 _logModelLoad: 0 _logRecording: 0 + _checkTime: 0.25 --- !u!114 &115404856 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Robot.cs b/Assets/Scripts/Robot.cs index 3a19d6a..539e39b 100644 --- a/Assets/Scripts/Robot.cs +++ b/Assets/Scripts/Robot.cs @@ -73,6 +73,8 @@ private void Awake() private void Start() { + Application.targetFrameRate = 30; + if (_autoStartRobot) InitializeRobot(); } diff --git a/Assets/Vendors/Vosk4Unity/Scripts/Yetibyte.Unity.SpeechRecognition/VoskListener.cs b/Assets/Vendors/Vosk4Unity/Scripts/Yetibyte.Unity.SpeechRecognition/VoskListener.cs index 0f57078..084e257 100644 --- a/Assets/Vendors/Vosk4Unity/Scripts/Yetibyte.Unity.SpeechRecognition/VoskListener.cs +++ b/Assets/Vendors/Vosk4Unity/Scripts/Yetibyte.Unity.SpeechRecognition/VoskListener.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -53,6 +54,8 @@ [SerializeField] [Header("Audio Settings")] [SerializeField] [Header("Misc.")] private VoskListenerDebugOptions _debugOptions = VoskListenerDebugOptions.CreateAllDisabled(); + [SerializeField] private float _checkTime = 0.25f; + #pragma warning restore CS0649 private VoskRecognizer _voskRecognizer; @@ -145,69 +148,78 @@ protected virtual void Start() { StartListening(); } + + StartCoroutine(UpdateLoop()); } - private void Update() + private IEnumerator UpdateLoop() { - if (IsListening && IsReady) + var wait = new WaitForSeconds(_checkTime); + + while (true) { - int micPos = Microphone.GetPosition(_listeningDevice); - - int sampleDelta = micPos >= _previousMicPosition - ? (micPos - _previousMicPosition) - : (_microphoneAudio.samples * _microphoneAudio.channels - (_previousMicPosition - micPos)); - - if (sampleDelta * FLOAT_BYTE_SIZE >= AudioChunkSize) + if (IsListening && IsReady) { - byte[] waveData = _microphoneAudio.GetWavData(sampleDelta, _previousMicPosition); + int micPos = Microphone.GetPosition(_listeningDevice); - int bufferCount = Mathf.CeilToInt(waveData.Length / (float) AudioChunkSize); + int sampleDelta = micPos >= _previousMicPosition + ? (micPos - _previousMicPosition) + : (_microphoneAudio.samples * _microphoneAudio.channels - (_previousMicPosition - micPos)); - bool cancel = false; - - for (int i = 0; i < bufferCount; i++) + if (sampleDelta * FLOAT_BYTE_SIZE >= AudioChunkSize) { - byte[] buffer = waveData.Skip(i * AudioChunkSize).Take(AudioChunkSize).ToArray(); + byte[] waveData = _microphoneAudio.GetWavData(sampleDelta, _previousMicPosition); + + int bufferCount = Mathf.CeilToInt(waveData.Length / (float) AudioChunkSize); - string result = string.Empty; + bool cancel = false; - if (_voskRecognizer.AcceptWaveform(buffer, buffer.Length)) + for (int i = 0; i < bufferCount; i++) { - _previousPartialResult = null; + byte[] buffer = waveData.Skip(i * AudioChunkSize).Take(AudioChunkSize).ToArray(); - result = _voskRecognizer.Result(); + string result = string.Empty; - _resultDeserializer.UseAlternatives = MaxAlternatives > 0; - VoskResult voskResult = _resultDeserializer.Deserialize(result); + if (_voskRecognizer.AcceptWaveform(buffer, buffer.Length)) + { + _previousPartialResult = null; - OnResultFound(voskResult); - } - else - { - result = _voskRecognizer.PartialResult(); + result = _voskRecognizer.Result(); - VoskPartialResult partialResult = _partialResultDeserializer.Deserialize(result); + _resultDeserializer.UseAlternatives = MaxAlternatives > 0; + VoskResult voskResult = _resultDeserializer.Deserialize(result); - if (partialResult != null && partialResult.Text != _previousPartialResult?.Text) + OnResultFound(voskResult); + } + else { - cancel = OnPartialResultFound(partialResult); - _previousPartialResult = partialResult; + result = _voskRecognizer.PartialResult(); - if (cancel) + VoskPartialResult partialResult = _partialResultDeserializer.Deserialize(result); + + if (partialResult != null && partialResult.Text != _previousPartialResult?.Text) { - result = _voskRecognizer.FinalResult(); + cancel = OnPartialResultFound(partialResult); + _previousPartialResult = partialResult; + + if (cancel) + { + result = _voskRecognizer.FinalResult(); - _resultDeserializer.UseAlternatives = MaxAlternatives > 0; - VoskResult voskResult = _resultDeserializer.Deserialize(result); + _resultDeserializer.UseAlternatives = MaxAlternatives > 0; + VoskResult voskResult = _resultDeserializer.Deserialize(result); - OnResultFound(voskResult); + OnResultFound(voskResult); + } } } } - } - _previousMicPosition = micPos; + _previousMicPosition = micPos; + } } + + yield return wait; } } diff --git a/Packages/packages-lock.json b/Packages/packages-lock.json index 95fe734..03bcf1a 100644 --- a/Packages/packages-lock.json +++ b/Packages/packages-lock.json @@ -31,7 +31,7 @@ "url": "https://packages.unity.com" }, "com.unity.burst": { - "version": "1.7.3", + "version": "1.7.4", "depth": 1, "source": "registry", "dependencies": { diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 87e731d..c7a6603 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -372,7 +372,7 @@ PlayerSettings: m_SubKind: m_BuildTargetBatching: - m_BuildTarget: Standalone - m_StaticBatching: 0 + m_StaticBatching: 1 m_DynamicBatching: 0 - m_BuildTarget: tvOS m_StaticBatching: 1 @@ -636,6 +636,7 @@ PlayerSettings: switchNetworkInterfaceManagerInitializeEnabled: 1 switchPlayerConnectionEnabled: 1 switchUseNewStyleFilepaths: 0 + switchUseLegacyFmodPriorities: 0 switchUseMicroSleepForYield: 1 switchEnableRamDiskSupport: 0 switchMicroSleepForYieldTime: 25 @@ -761,7 +762,7 @@ PlayerSettings: platformArchitecture: {} scriptingBackend: Android: 1 - Standalone: 1 + Standalone: 0 il2cppCompilerConfiguration: Standalone: 2 il2cppCodeGeneration: {} diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt index df0a387..e984f8c 100644 --- a/ProjectSettings/ProjectVersion.txt +++ b/ProjectSettings/ProjectVersion.txt @@ -1,2 +1,2 @@ -m_EditorVersion: 2022.2.0f1 -m_EditorVersionWithRevision: 2022.2.0f1 (35dcd44975df) +m_EditorVersion: 2022.2.1f1 +m_EditorVersionWithRevision: 2022.2.1f1 (4fead5835099) diff --git a/ProjectSettings/QualitySettings.asset b/ProjectSettings/QualitySettings.asset index 12b67a3..5fb17b7 100644 --- a/ProjectSettings/QualitySettings.asset +++ b/ProjectSettings/QualitySettings.asset @@ -6,29 +6,32 @@ QualitySettings: serializedVersion: 5 m_CurrentQuality: 0 m_QualitySettings: - - serializedVersion: 2 + - serializedVersion: 3 name: High - pixelLightCount: 2 + pixelLightCount: 1 shadows: 2 shadowResolution: 1 shadowProjection: 1 - shadowCascades: 2 + shadowCascades: 1 shadowDistance: 40 shadowNearPlaneOffset: 3 shadowCascade2Split: 0.33333334 shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667} shadowmaskMode: 0 - skinWeights: 2 - textureQuality: 0 + skinWeights: 4 + globalTextureMipmapLimit: 0 + textureMipmapLimitSettings: [] anisotropicTextures: 1 antiAliasing: 0 softParticles: 0 softVegetation: 1 - realtimeReflectionProbes: 1 - billboardsFaceCameraPosition: 1 - vSyncCount: 0 + realtimeReflectionProbes: 0 + billboardsFaceCameraPosition: 0 + useLegacyDetailDistribution: 0 + vSyncCount: 1 lodBias: 1 maximumLODLevel: 0 + enableLODCrossFade: 0 streamingMipmapsActive: 0 streamingMipmapsAddAllCameras: 1 streamingMipmapsMemoryBudget: 512 @@ -41,7 +44,17 @@ QualitySettings: asyncUploadPersistentBuffer: 1 resolutionScalingFixedDPIFactor: 1 customRenderPipeline: {fileID: 0} + terrainQualityOverrides: 0 + terrainPixelError: 1 + terrainDetailDensityScale: 1 + terrainBasemapDistance: 1000 + terrainDetailDistance: 80 + terrainTreeDistance: 5000 + terrainBillboardStart: 50 + terrainFadeLength: 5 + terrainMaxTrees: 50 excludedTargetPlatforms: [] + m_TextureMipmapLimitGroupNames: [] m_PerPlatformDefaultQuality: Android: 0 Lumin: 0