I'm coding a gamification application where the interactions with the end user is performed with microphone and webcam. I'm using a 2019 mac mini with unity 3D 2018.
During the coding session with the unity editor everything works fine, but when I build for deployment the application becomes too slow and freezes when it tries to access webcam and microphone.
I gave all permissions for using these devices.
The build-ed application works well with windows and android.
Why I cannot use Microphone with the deployed app on MacOS?
The same code works good on other platform.
Below I publish the piece of code in which I use the microphone:
public void onPointerDown()
{
mSpeechToTextManagerGoogle.audioSource.clip = Microphone.Start("", true, 30, 44100);
mSpeechToTextManagerGoogle.start = Time.time;
mSpeechToTextManagerGoogle.audioSource.loop = true;
while (!(Microphone.GetPosition(null) > 0))
{
}
}
public void onPointerUp()
{
Microphone.End("");
mSpeechToTextManagerGoogle.end = Time.time;
StartCoroutine(mSpeechToTextManagerGoogle.SendRequestToGoogle(mSpeechToTextManagerGoogle.audioSource.clip, 0, (mSpeechToTextManagerGoogle.end - mSpeechToTextManagerGoogle.start)));
}
Try with this:
mSpeechToTextManagerGoogle.audioSource.clip = Microphone.Start("Built-in Microphone", true, 30, 44100);
Related
I am running into an issue with my C# WPF application crashing silently when I am trying to play on 16 VideoViews. I did not see any error messaged popup, nor did I see anything in Windows Event viewer.
Each player instance have WindowsFormHost and hosting a VideoView in that and I am playing RTSP streams on them.
Crash time is not fixed, sometimes it crash after 2 hours, and sometimes after 7-8 hours.
Core.Initialize(AppInfo.VlcDir.FullName);
private LibVLC libVlc = null;
private LibVLCSharp.Shared.MediaPlayer mediaPlayer = null;
this.libVlc = new LibVLC(this.GetParsedPlayerOptions().ToArray());
this.mediaPlayer = new LibVLCSharp.Shared.MediaPlayer(this.libVlc);
this.videoPlayer.MediaPlayer = this.mediaPlayer;
this.mediaPlayer.Volume = 0;
this.mediaPlayer.EnableKeyInput = false;
this.mediaPlayer.EnableMouseInput = false;
// Then I added a bunch of event handlers for VideoView and MediaPlayer.
// Then I have a different function which plays videos
if (this.mediaPlayer != null)
{
var media = new Media(this.libVlc,GetPlaybackStreamUrl(this.Server), FromType.FromLocation);
this.mediaPlayer.Media = media;
this.mediaPlayer.Play();
try
{
media.Dispose();
}
catch
{
}
}
Please let me know if you need any more information.
Any suggestions of what I could be doing wrong, or anything missing?
I am running on Windows 10. Visual Studio 2019, application compiled as X86.
I am not able to find the option to upload log file, but I did attach that to the issue on videolan forum, which can be found here: https://code.videolan.org/videolan/LibVLCSharp/-/issues/564
Thanks.
I was not able to find the problem with the code or the crash stack for where it's dying.
But I was able to fix the problem by increasing the address space, by using editbin to add /LARGEADDRESSSPACE to process post build.
I have Lumia 830 and i've tried to create flashlight app in UWP C#. my device Flashlight works great but i don't know why i can't create my own app turn on / off Torch of my phone.
I use Lamp class :
var lamp = await Lamp.GetDefaultAsync();
if (lamp == null)
{
ShowErrorMessage("No Lamp device found");
return;
}
lamp.IsEnabled = true;
when run this code on my phone "lamp" is null and it couldn't find my FlashLED. I've got this code from MSDN.Microsoft.com and thay said
If the returned object is null, the Lamp API is unsupported on the
device. Some devices may not support the Lamp API even if there is a
lamp physically present on the device.
This class doesn't work on my Lumia 830 i don't kno why? :(
also i use this code :
var mediaDev = new MediaCapture();
await mediaDev.InitializeAsync();
var videoDev = mediaDev.VideoDeviceController;
var tc = videoDev.TorchControl;
if (tc.Supported)
{
// But wait, for this to work with Blue camera drivers, we have to Start a recording session
// Create video encoding profile as MP4
var videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga);
// Start Video Recording
var videoStorageFile = await KnownFolders.VideosLibrary.CreateFileAsync("tempVideo.mp4", CreationCollisionOption.GenerateUniqueName);
await mediaDev.StartRecordToStorageFileAsync(videoEncodingProperties, videoStorageFile);
// Turn on Torch
mediaDev.VideoDeviceController.TorchControl.Enabled = true;
}
this code works and my FlashLED turn on but it record video and it take's user SD Card memory.
please help me if you know there is best way to turn on/off Torch or FlashLED.
thanks in advance
Hussein Habibi Juybari
The Lamp API is designed for Windows 10 devices only and you can only use it on devices which support the API. Currently supported devices are 950/950XL, 650, and 550. Older devices will not be updated to support this API. You should fall back to the Windows 8.1 method of turning on flash when you detect that the lamp device is not available on older devices.
From: https://wpdev.uservoice.com/forums/110705/suggestions/15846967
Please test default sample named LampDevice (cf. https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/LampDevice). Do you have the same behavior ? I just tested on Lumia 930 it works fine. No Lumia 830 to test it.
For some reason I cannot get Monogame to play any sounds through SoundEffect or SoundEffectInstance.
With a workaround I can get Songs to play, but still not SoundEffects or SoundEffectInstances.
If I run my example below through “native XNA” everything works fine.
I’m using:
Monogame 3.2 for Windows Desktop (DirectX)
Windows 7
Visual Studio Express 2013
Example:
SoundEffect effect;
SoundEffectInstance instance;
Song song;
protected override void LoadContent()
{
// Load sound, no errors and the objects get filled with data.
effect = Content.Load<SoundEffect>("myWavFileAsSoundEffect"); // Loaded with ContentProcessor = "Sound Effect - XNA Framework"
song = Content.Load<Song>("myWavFileAsSong"); // Loaded with ContentProcessor = "Song - XNA Framework"
instance = effect.CreateInstance();
// Set volume to 100%, just in case
SoundEffect.MasterVolume = 1.0f;
MediaPlayer.Volume = 1.0f;
instance.Volume = 1.0f;
}
protected override void Update(GameTime gameTime)
{
if (Keyboard.GetState().IsKeyDown(Keys.Space))
{
// Play instance. Nothing happens.
instance.Play();
// Play effect. Nothing happens.
bool success = effect.Play(1.0f, 0.0f, 0.0f);
// success is true
// Play song.
try
{
// Error
// HRESULT: [0x80004002], Module: [General], ApiCode: [E_NOINTERFACE/No such interface supported]
MediaPlayer.Play(song);
}
catch (Exception)
{
// Play the song again
// Plays fine
MediaPlayer.Play(song);
}
}
base.Update(gameTime);
}
Does anyone know what might be wrong? Why can’t I play any SoundEffects or SoundEffectInstances?
I had the exact same problem but on Windows 10. The solution for me was to reinstall Directx.
Webinstaller: https://www.microsoft.com/en-us/download/details.aspx?id=35&84e4d527-1a2f-c70a-8906-a877ec4baada=1
Hope this helps
Even I was having problem with when added .wav files.But when I added .xnb files which is generated after building the XNA project(files are in bin\content folder),errors gone.Could you please try with xnb files.
I'm trying to get touch positions in a MonoGame I'm running on a windows Phone 8 device and debugging through Visual Studio 2012.
This is my update method:
public override void Update(Microsoft.Xna.Framework.GameTime time)
{
if (_StateIsActive) // for pausing game
{
base.Update(time);
TouchCollection touchCollection = TouchPanel.GetState();
foreach (TouchLocation tl in touchCollection)
{
if ((tl.State == TouchLocationState.Pressed)
|| (tl.State == TouchLocationState.Moved))
{
Debug.WriteLine(tl.Position.ToString());
}
}
}
}
When I touch the screen all I get in the output is:
{X:INF Y:INF}
What am I doing wrong?
EDIT: I tried to do what has been done in this thread, but it wont work as I only get the INF value. MonoGame reading touch gestures
The answer seems to be that there is a bug in this version of Mono Game (3.0.1.0) related to this and that it will be fixed with a new release within the next few days.
Source: #MonoGame channel on IRC and their forums.
I wanted to know, what would the coding be if I wanted to toggle mute/unmute of my microphone. I am making a program that can run in the background and pickup a keypress event and toggle mute/unmute of the mic. Any help with any of that coding would be very helpful. I am pretty new to C#, and this is just a really simple program I wanted to make. That is all it does, is it will listen for keypress of the spacebar, even when the program is in the background, then when the spacebar is pressed it will mute/unmute the mic.
Thank you for any and all help!
For Windows Vista and newer, you can no longer use the Media Control Interface, Microsoft has a new Core Audio API that you must access to interface with audio hardware in these newer operating systems.
Ray Molenkamp wrote a nice managed wrapper for interfacing with the Core Audio API here:
Vista Core Audio API Master Volume Control
Since I needed to be able to mute the microphone from XP, Vista and Windows 7 I wrote a little Windows Microphone Mute Library which uses Ray's library on the newer operating systems and parts of Gustavo Franco's MixerNative library for Windows XP and older.
You can download the source of a whole application which has muting the microphone, selecting it as a recording device, etc.
http://www.codeguru.com/csharp/csharp/cs_graphics/sound/article.php/c10931/
you can use MCI (Media Control Interface) to access mics and change their volume system wise. Check the code below it should be setting volume to 0 for all system microphones. Code is in c; check pinvoke for details on how to translate this code to c#
#include "mmsystem.h"
...
void MuteAllMics()
{
HMIXER hmx;
mixerOpen(&hmx, 0, 0, 0, 0);
// Get the line info for the wave in destination line
MIXERLINE mxl;
mxl.cbStruct = sizeof(mxl);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
// find the microphone source line connected to this wave in destination
DWORD cConnections = mxl.cConnections;
for (DWORD j=0; j<cConnections; j++)
{
mxl.dwSource = j;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
if (MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE == mxl.dwComponentType)
{
// Find a volume control, if any, of the microphone line
LPMIXERCONTROL pmxctrl = (LPMIXERCONTROL)malloc(sizeof MIXERCONTROL);
MIXERLINECONTROLS mxlctrl =
{
sizeof mxlctrl,
mxl.dwLineID,
MIXERCONTROL_CONTROLTYPE_VOLUME,
1,
sizeof MIXERCONTROL,
pmxctrl
};
if (!mixerGetLineControls((HMIXEROBJ) hmx, &mxlctrl, MIXER_GETLINECONTROLSF_ONEBYTYPE))
{
DWORD cChannels = mxl.cChannels;
if (MIXERCONTROL_CONTROLF_UNIFORM & pmxctrl->fdwControl)
cChannels = 1;
LPMIXERCONTROLDETAILS_UNSIGNED pUnsigned = (LPMIXERCONTROLDETAILS_UNSIGNED)
malloc(cChannels * sizeof MIXERCONTROLDETAILS_UNSIGNED);
MIXERCONTROLDETAILS mxcd =
{
sizeof(mxcd),
pmxctrl->dwControlID,
cChannels,
(HWND)0,
sizeof MIXERCONTROLDETAILS_UNSIGNED,
(LPVOID) pUnsigned
};
mixerGetControlDetails((HMIXEROBJ)hmx, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
// Set the volume to the middle (for both channels as needed)
//pUnsigned[0].dwValue = pUnsigned[cChannels - 1].dwValue = (pmxctrl->Bounds.dwMinimum+pmxctrl->Bounds.dwMaximum)/2;
// Mute
pUnsigned[0].dwValue = pUnsigned[cChannels - 1].dwValue = 0;
mixerSetControlDetails((HMIXEROBJ)hmx, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
free(pmxctrl);
free(pUnsigned);
}
else
{
free(pmxctrl);
}
}
}
mixerClose(hmx);
}
here you can find more code on this topic
hope this helps, regards
I have several microphones in win7 and class WindowsMicrophoneMuteLibrary.CoreAudioMicMute is incorrect in this case.
so I change the code and works great because now his cup Whistle all microphones and not just in the last recognized by win7.
I am attaching the new class to put in place.
http://www.developpez.net/forums/d1145354/dotnet/langages/csharp/couper-micro-sous-win7/