Check if an application emits sound - c#
today I am here to ask you how you can "understand" if a given application is emitting sound.
On windows 7 and 8 I use the following code (library CSCore Audio )
[...]
AudioSessionManager2 sessionManager = GetDefaultAudioSessionManager2(DataFlow.Render);
AudioSessionEnumerator sessionEnumerator = sessionManager.GetSessionEnumerator();
AudioSessionControl2 sessionControl;
foreach (AudioSessionControl session in sessionEnumerator)
{
sessionControl = session.QueryInterface<AudioSessionControl2>();
if (sessionControl.Process.MainWindowTitle.StartsWith("my_test"))
{
sessione = sessionControl;
audio = session.QueryInterface<AudioMeterInformation>();
break;
}
}
control.Text = sessione.Process.MainWindowTitle + "[" + audio.PeakValue + "]";
[...]
It works well, but not on Windows XP.
Is there a way "universal" to do it?
If there would be a way to do this in Java would be even better, so work on Linux (which for the moment I do not need, but maybe in the future)
I am sorry, but Windows XP does not querying the audio peak of a process. You can also take a look at the Windows XP Audio Mixer. There is no peak displayed.
Related
How to get and use full installed text-to-speech languages list?
There is something really weird happening in Windows 10 speech synthesis. First of all, even Windows displays different installed languages count in metro and classic control panels. Metro app shows 5 installed languages, while classic control panel shows only 3. I need to use Microsoft Pavel language, but my app simply don't see it! SpeechSynthesizer ss = new SpeechSynthesizer(); var installed_voices = ss.GetInstalledVoices(); for (int i = 0; i < installed_voices.Count; i++) Console.WriteLine(GetVoiceInfoDesc(installed_voices[i].VoiceInfo)); static string GetVoiceInfoDesc(VoiceInfo vi) { return vi.AdditionalInfo["Name"] + " (ID = " + vi.AdditionalInfo["Language"] + ", " + vi.AdditionalInfo["Age"] + ", " + vi.AdditionalInfo["Gender"] + ", " + vi.Culture + ")"; } The code above displays only 3 installed languages. Also, when I use ss.SelectVoiceByHints(VoiceGender.Male, VoiceAge.Adult, 0, CultureInfo.CreateSpecificCulture("ru-RU")); I still get Irina voice that is female. I tested Pavel's voice and it's really installed and speaks something. I use .net 4.0 C#. Any ideas what's happening here?
The problem that is some languages for some unknown reason can be used in metro apps only and can't be seen through SAPI. We can fix this by changing registry. This is fix example for Windows 10 x64 Pavel's voice that I took from somewhere in Internet: Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Speech\Voices\Tokens\MSTTS_V110_ruRU_PavelM] #="Microsoft Pavel Mobile - Russian (Russia)" "419"="Microsoft Pavel Mobile - Russian (Russia)" "CLSID"="{179F3D56-1B0B-42B2-A962-59B7EF59FE1B}" "LangDataPath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,\ 00,70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,\ 65,00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,\ 00,5c,00,72,00,75,00,2d,00,52,00,55,00,5c,00,4d,00,53,00,54,00,54,00,53,00,\ 4c,00,6f,00,63,00,72,00,75,00,52,00,55,00,2e,00,64,00,61,00,74,00,00,00 "VoicePath"=hex(2):25,00,77,00,69,00,6e,00,64,00,69,00,72,00,25,00,5c,00,53,00,\ 70,00,65,00,65,00,63,00,68,00,5f,00,4f,00,6e,00,65,00,43,00,6f,00,72,00,65,\ 00,5c,00,45,00,6e,00,67,00,69,00,6e,00,65,00,73,00,5c,00,54,00,54,00,53,00,\ 5c,00,72,00,75,00,2d,00,52,00,55,00,5c,00,4d,00,31,00,30,00,34,00,39,00,50,\ 00,61,00,76,00,65,00,6c,00,00,00 [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Speech\Voices\Tokens\MSTTS_V110_ruRU_PavelM\Attributes] "Age"="Adult" "DataVersion"="11.0.2013.1022" "Gender"="Male" "Language"="419" "Name"="Microsoft Pavel Mobile" "SharedPronunciation"="" "Vendor"="Microsoft" "Version"="11.0" Readme says "Thanks to Nonna Lavrukhina".
I had the same problem and tried multiple solutions but none of them worked. My requirement was not to have the specific voices found in windows 10 so i looked for other resources and found this. I have tried installing some of them and my application recognizes them as being installed and they work as expected. Maybe you can find some voices there that suits your needs. Good luck!
How can I determine bandwidth on Windows 7, 8.1 and 10?
So far I have struggled to get MbnInterfaceManager working (see hresult from IMbnInterfaceManager::GetInterfaces when no MBN device exists), so instead I built and debugged an application with no problems from within Visual Studio 2015 that executed this WMI query in C# (see also the Win32_PerfFormattedData_Tcpip_NetworkInterface documentation): string query = "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface"; ManagementObjectSearcher moSearch = new ManagementObjectSearcher(query); ManagementObjectCollection moCollection = moSearch.Get(); But then when I deployed the application to Windows 8.1, I receive this error every time the query is executed: System.Management.ManagementException: Invalid query at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() Does anyone have any suggestions on how to resolve this issue? How can I deploy an application so that it is able to use queries like this? UPDATE: Please note that I can build and run the above code (as part of a larger WPF application) from within Visual Studio 2015 on either Windows 7 or Windows 8.1, and I can deploy the same application using ClickOnce onto Windows 7 where it runs successfully. For some reason when I deploy this application using ClickOnce onto Windows 8.1, I get that Invalid query message.
I think what I have to do is make sure that the System.Management reference is set to "Copy Local" but I'm not able to test that right now. If anyone has any better ideas please feel free to let me know. UPDATE: It is not possible to use System.Management.dll on Windows 8.1 in the same way it is used on Windows 7 or Windows 10. I've found that to perform operations similar to the ones I mentioned in my question on Windows 8.1 and Windows 8 phone you need to either get a Windows 8.1 developer license or on Windows 10 set your computer to "Developer Mode" so you can use the Windows.Networking.Connectivity namespace: string connectionProfileInfo = string.Empty; ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); if (InternetConnectionProfile == null) { rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage); } else { connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile); OutputText.Text = connectionProfileInfo; rootPage.NotifyUser("Success", NotifyType.StatusMessage); } // Which calls this function, that allows you to determine how strong the signal is and the associated bandwidth string GetConnectionProfile(ConnectionProfile connectionProfile) { // ... if (connectionProfile.GetSignalBars().HasValue) { connectionProfileInfo += "====================\n"; connectionProfileInfo += "Signal Bars: " + connectionProfile.GetSignalBars() + "\n"; } // ... } Please note that you have to make sure your project is either a Window 8.1 PCL or a Windows 8.1 app to be able to reference the namespace. For details please see https://code.msdn.microsoft.com/windowsapps/network-information-sample-63aaa201 UPDATE 2: To be able to get bandwidth on Windows 7, 8.1 and 10, I ended up using this code: private int GetMaxBandwidth() { int maxBandwidth = 0; NetworkInterface[] networkIntrInterfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (var networkInterface in networkIntrInterfaces) { IPv4InterfaceStatistics interfaceStats = networkInterface.GetIPv4Statistics(); int bytesSentSpeed = (int)(interfaceStats.BytesSent); int bytesReceivedSpeed = (int)(interfaceStats.BytesReceived); if (bytesSentSpeed + bytesReceivedSpeed > maxBandwidth) { maxBandwidth = bytesSentSpeed + bytesReceivedSpeed; } } }
How to detect Windows Phone 8.1 OS version programmatically?
The question in title is not the real problem. I went through many sites and blogs and go to know that Environment.OSVersion gives you the current OS version of the phone using our app. But the problem is, There is no OSVersion under the class Environment. Please refer the screenshot for better understanding. My question why I am not able to see the OSVersion property under Environment class? Am I missing something?
Universal/WinRT apps only work in wp 8.1, so the OS version can only be 8.1. When they make wp8.2 or wp9, they'll probably add a way to check what OS version is installed... If you're looking for the firmware version, you can get it with: Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation deviceInfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation(); var firmwareVersion = deviceInfo.SystemFirmwareVersion;
Copied from duped question: Windows Phone 8.1 Silverlight apps can use the .NET version APIs. There is no supported mechanism to get a version number in Universal 8.1 apps, but you can try using reflection to get the Windows 10 AnalyticsInfo class, which will at least tell you the version number if you are running on Windows 10. Note: Checking the OS version is almost always the wrong thing to do, unless you're simply displaying it to the user (eg, in an "About" box) or sending it to your back-end analytics server for number crunching. It should not be used to make any run-time decisions, because in general it's a poor proxy for whatever-you're-actually-trying-to-do. Here is a sample: var analyticsInfoType = Type.GetType( "Windows.System.Profile.AnalyticsInfo, Windows, ContentType=WindowsRuntime"); var versionInfoType = Type.GetType( "Windows.System.Profile.AnalyticsVersionInfo, Windows, ContentType=WindowsRuntime"); if (analyticsInfoType == null || versionInfoType == null) { Debug.WriteLine("Apparently you are not on Windows 10"); return; } var versionInfoProperty = analyticsInfoType.GetRuntimeProperty("VersionInfo"); object versionInfo = versionInfoProperty.GetValue(null); var versionProperty = versionInfoType.GetRuntimeProperty("DeviceFamilyVersion"); object familyVersion = versionProperty.GetValue(versionInfo); long versionBytes; if (!long.TryParse(familyVersion.ToString(), out versionBytes)) { Debug.WriteLine("Can't parse version number"); return; } Version uapVersion = new Version((ushort)(versionBytes >> 48), (ushort)(versionBytes >> 32), (ushort)(versionBytes >> 16), (ushort)(versionBytes)); Debug.WriteLine("UAP Version is " + uapVersion); Obviously you can update this to return the version etc. rather than print it to the debug console.
You cannot get the OS Version in Windows 8.1 .Check the following link for the same - https://social.msdn.microsoft.com/Forums/windowsapps/en-US/2b455331-3bad-4d26-b615-a59d0e05d0dd/how-to-get-os-version-on-window-phone?forum=wpdevelop
I found a tricky way to detect if a device is running a Windows Phone 8.1 or Windows Phone 10. I compared 3 different devices, a Nokia Lumia 925 ( wp 8.1 ) a Nokia Lumia 735 ( wp 10 ) and a Nokia Lumia 930 ( wp 10 ). I noticed that on wp8.1 there is no device info id ( it causes a not implemented exception ) but it exists on windows phone 10 on both tested devices. Morover the system firmware version format seems different between wp 8.1 and wp 10 ( the first is xxxx.xxxxx.xxxx.xxxx while the second is xxxxx.xxxxx.xxxxx.xxxxx ). Below my function: /// <summary> /// Indicates if this device is running a version of Windows Phone 8.1. It use a dirty trick for detecting the OS major version /// based on the system firmware version format (8.1 is xxxx.xxxxx.xxxx.xxxx while 10 is xxxxx.xxxxx.xxxxx.xxxxx ) /// moreover, the "deviceInfo.id" is not implemented on Windows Phone 8.1, but it is on Windows Phone 10 /// </summary> /// <returns></returns> public static bool liIsWindowsPhone81(bool basedOnDeviceInfoId) { EasClientDeviceInformation deviceInfo = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation(); bool isWin81 = false; if (basedOnDeviceInfoId) { try { var deviceInfoId = deviceInfo.Id; } catch { isWin81 = true; } } else { string firmwareVersion = deviceInfo.SystemFirmwareVersion.Trim(); string[] parts = firmwareVersion.Split('.'); if (parts[0].Length == 4 && parts[1].Length == 5 && parts[2].Length == 4 && parts[3].Length == 4) { isWin81 = true; } } return isWin81; } I haven't had the opportunity to test this on further devices, but so far seems to work. I use it to distinguish the code for the app rating function between Windows Phone 8.1 and Windows Phone 10, that in my specific case are not UWP Hope this helps
If your app is Silverlight based, you can use System.Environment.OSVersion.Version across Windows Phone 8.0 and 8.1 as well as Windows Mobile 10. Here is an example of a method we utilize when determining whether to display our own opt-in dialog for geo-tracking or let the Windows Mobile 10 present its own opt-in dialog. public static bool IsWindowsPhone8x() { try { Version version = System.Environment.OSVersion.Version; return version.Major > 8 ? false : true; } catch (Exception) { return false; } }
Simply use this line to get the Application Name and Id, publisher name etc... string name = Windows.ApplicationModel.Package.Current.DisplayName;
struggling with mobile broadband api windows 7 and windows 8 with C#, not sure what to install
I have an application that requires to control mobile broadband API. I am struggling on correctly installing the api on my devices. I've been follow the instructions in this document: http://www.google.be/url?sa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=1&cad=rja&ved=0CC0QFjAA&url=http%3A%2F%2Fdownload.microsoft.com%2Fdownload%2F7%2FE%2F7%2F7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2%2FMB_ManagedCode.docx&ei=kyvmUs7jE4e60QWbooHYDg&usg=AFQjCNG6yaGf4sRhdbWI99fE7tmQX8cmnA&sig2=2Fg-_DRYBIselKR19wTq2Q and trying to combine the steps with this stackoverflow explanation C# Read Windows Mobile Broadband connection properties I have been able to lay a reference from visual studio to mbnapi.tlb in V7.0/lib. and I automatically now have a interop.mbnapi.tlb in my obj/debug folder. When trying to "check the SIM is inserted and working / activated". => my code crashes on the following line IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[]; When I run it on windows 8, mbnInfMgrInterface == null I have already tried to install the same SDK on windows 8 as stated in the requirements of the document but the SDK is only meant for windows 7... I have tried to register the mbnapi in windows 8 by performing Regtlibv12 Mbnapi.tlb no luck whatsoever... what do I need to do to get this to work please? anyone has some experience in this? EDIT. on windows 7 (my development machine), I get the message "Device not ready", I think this is normal because I don't have mobile broadband on it, on windows 8 I do, but there the mobile interface manager is null => mbnInfMgrInterface == null. thank you,
Not sure exactly what you are after, but after struggling with IMbnInterface and GetSignalStrength() (see https://msdn.microsoft.com/en-us/library/windows/desktop/dd323166(v=vs.85).aspx) and being unsuccessful, I found that you can obtain a lot of info using WMI: int maxBandwidth = 0; string query = "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface"; ManagementObjectSearcher moSearch = new ManagementObjectSearcher(query); ManagementObjectCollection moCollection = moSearch.Get(); foreach (ManagementObject mo in moCollection) { if (Convert.ToInt32(mo["CurrentBandwidth"]) > maxBandwidth) { // Instead of CurrentBandwidth you may want to use BytesReceivedPerSec maxBandwidth = Convert.ToInt32(mo["CurrentBandwidth"]); } } Please see answer here: Determining the network connection link speed and here is the list of properties you can obtain: https://msdn.microsoft.com/en-us/library/aa394293(VS.85).aspx UPDATE: Please note that I can build and debug the above code (as part of a larger WPF application) from within Visual Studio 2015 on either Windows 7 or Windows 8.1, and I can deploy the same application onto Windows 7 where it runs successfully. For some reason when I deploy this application on Windows 8.1, I get an Invalid query message. UPDATE 2: Please note that I found you cannot get the network info in Windows 8.1 in the same way as you do in Windows 7, in that the System.Management namespace is not available on Windows 8.1. See https://code.msdn.microsoft.com/windowsapps/network-information-sample-63aaa201 string connectionProfileInfo = string.Empty; ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); if (InternetConnectionProfile == null) { rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage); } else { connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile); OutputText.Text = connectionProfileInfo; rootPage.NotifyUser("Success", NotifyType.StatusMessage); } // Which calls this function, that allows you to determine how strong the signal is and the associated bandwidth string GetConnectionProfile(ConnectionProfile connectionProfile) { // ... if (connectionProfile.GetSignalBars().HasValue) { connectionProfileInfo += "====================\n"; connectionProfileInfo += "Signal Bars: " + connectionProfile.GetSignalBars() + "\n"; } // ... }
HASP HL working demo needed for C#
Okay. Well, I know this question has a good chance of being closed within the first 10 minutes, but I am going to ask it anyways for I have spent almost day and an half trying to find a solution. Still, I can't figure this one out. There is not much info on this on the Internet not even on the HASP (safenet) website although they have demos. I have a HASP HL USB dongle. I try to convert their demo and test run it but for the life of me I simply can't get it to login even. It keeps raising Aladdin.HASP.HaspStatus.HaspDotNetDllBroken exception. However, if I run the C version of their demo, it works perfectly. Here is the Csharp version of my code: Aladdin.HASP; HASP myHasp = new HASP(); var thestatus = myHasp.Login(vender_code); myHasp.Logout; I would like to login to USB HASP and get its HaspID and the settings in its memory. Thanks in advance,
It might be that you aren't having all dependencies for the HASP runtime. I'm packing with the app: hasp_windows_NNNNN.dll (NNNNN = your number) hasp_net_windows.dll MSVCR71.DLL (added manually) msvc runtime 80 One runtime library is required by HASP and it doesn't tell you which one unless you put it in the DEPENDS.EXE utility (you probably have you on your Visual Studio installation). To log in (and read some bytes): byte[] key = new byte[16]; HaspFeature feature = HaspFeature.FromFeature(4); string vendorCode = "your vendor string, get it from your tools"; Hasp hasp = new Hasp(feature); HaspStatus status = hasp.Login(vendorCode); if (HaspStatus.StatusOk != status) { // no license to run return false; } else { // read some memory here HaspFile mem = hasp.GetFile(HaspFileId.ReadOnly); mem.Read(key, 0, 16); status = hasp.Logout(); if (HaspStatus.StatusOk != status) { //handle error } } Hope it helps. My HASPed software works like a charm. BTW, wasn't able to put envelope around .NET app under no combination of settings.