Jump to content
Subz

Get Audio/Microphone Devices [Solved]

Recommended Posts

Hello all.

in the process of packaging an application (Voip) and looking at trying to automate capturing the following information to add to a config.xml file:

Default: Playback Device Name and Guid
Example:
Name: Speakers (Realtek High Definition Audio)
Guid: {0.0.0.00000000}.{a46ce930-4dd3-49b5-8e8e-7c8a2fdc3925}

Default Microphone Device Name and Guid
Example:
Name: Microphone (Realtek High Definition Audio)
Guid: {0.0.1.00000000}.{cff6f838-33ce-4c2d-9f77-98f4e19e4a75}

I've seen the following post by @trancexx, which gives me the Default Audit Device Name, but unsure how to get the Guid or the Microphone Name and Guid.  I believe to get the Guid, I would need to use PKEY_AudioEndpoint_GUID but unsure how to code this.  If anyone can assist or point me in the right direction it would be much appreciated.

Cheers Subz

 

Edited by Subz

Share this post


Link to post
Share on other sites

Thats a nice example from Trancexx there

I believe you just need to pass the Correct Property Key

Global Const $sPKEY_Device_FriendlyName = "{a45c254e-df1c-4efd-8020-67d146a850e0}, 14"
Global Const $sPKEY_Audio_Endpoint_GUID = "{1DA5D803-D492-4EDD-8C23-E0C0FFEE7F0E}, 4"

like literally use $sPKEY_Audio_Endpoint_GUID instead of $sPKEY_Device_FriendlyName

Share this post


Link to post
Share on other sites

sorry I missed the part about you wanting the microphone as well

#include <WinAPICOM.au3>


Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"
Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(int;int;ptr*);" & _
        "GetDefaultAudioEndpoint hresult(int;int;ptr*);" & _
        "GetDevice hresult(wstr;ptr*);" & _
        "RegisterEndpointNotificationCallback hresult(ptr);" & _
        "UnregisterEndpointNotificationCallback hresult(ptr);"

Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = "Activate hresult(ptr;dword;variant*;ptr*);" & _
        "OpenPropertyStore hresult(dword;ptr*);" & _
        "GetId hresult(ptr*);" & _
        "GetState hresult(dword*);"

Global Const $IID_IPropertyStore = "{886d8eeb-8cf2-4446-8d02-cdba1dbdcf99}"
Global Const $tagIPropertyStore = "GetCount hresult(dword*);" & _
        "GetAt hresult(dword;ptr*);" & _
        "GetValue hresult(struct*;variant*);" & _
        "SetValue hresult(struct*;variant);" & _
        "Commit hresult();"

Global Const $sPKEY_Device_FriendlyName = "{a45c254e-df1c-4efd-8020-67d146a850e0}, 14"
Global Const $sPKEY_Audio_Endpoint_GUID = "{1DA5D803-D492-4EDD-8C23-E0C0FFEE7F0E}, 4"

Global Const $STGM_READ = 0
Global Const $DEVICE_STATE_ACTIVE = 0x00000001

Global Const $eRender = 0
Global Const $eCapture = 1
Global Const $eAll = 2
Global Const $EDataFlow_enum_count = 3

Global Const $eConsole = 0
Global Const $eMultimedia = 1
Global Const $eCommunications = 2
Global Const $ERole_enum_count = 3

Func _WinAPI_PKEYFromString($sPKEY, $pID = Default)
    Local $tPKEY = DllStructCreate("byte GUID[16]; dword PID;")
    DllCall("propsys.dll", "long", "PSPropertyKeyFromString", "wstr", $sPKEY, "struct*", $tPKEY)
    If $pID <> Default Then DllStructSetData($tPKEY, "PID", $pID)
    Return $tPKEY
EndFunc
;==========================================================

Local $oEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)

Local $pDefaultEndpoint
$oEnumerator.GetDefaultAudioEndpoint($eRender, $DEVICE_STATE_ACTIVE, $pDefaultEndpoint)

Local $oEndpoint = ObjCreateInterface($pDefaultEndpoint, $IID_IMMDevice, $tagIMMDevice)

; PropertyStore stores properties
Local $pProps
$oEndpoint.OpenPropertyStore($STGM_READ, $pProps)
$oProps = ObjCreateInterface($pProps, $IID_IPropertyStore, $tagIPropertyStore)

; Collect FriendlyName property
Local $tPKEY_Device_FriendlyName = _WinAPI_PKEYFromString($sPKEY_Device_FriendlyName)
Local $sName
$oProps.GetValue($tPKEY_Device_FriendlyName, $sName)

ConsoleWrite($sName & @CRLF)

Local $tPKEY_Audio_Endpoint_GUID = _WinAPI_PKEYFromString($sPKEY_Audio_Endpoint_GUID)
Local $sGuid
$oProps.GetValue($tPKEY_Audio_Endpoint_GUID, $sGuid)

ConsoleWrite($sGuid & @CRLF)

;------------MICROPHONE
$oEnumerator.GetDefaultAudioEndpoint($eCapture, $DEVICE_STATE_ACTIVE, $pDefaultEndpoint)

$oEndpoint = ObjCreateInterface($pDefaultEndpoint, $IID_IMMDevice, $tagIMMDevice)

; PropertyStore stores properties
$oEndpoint.OpenPropertyStore($STGM_READ, $pProps)

$oProps = ObjCreateInterface($pProps, $IID_IPropertyStore, $tagIPropertyStore)

; Collect FriendlyName property
$tPKEY_Device_FriendlyName = _WinAPI_PKEYFromString($sPKEY_Device_FriendlyName)

$oProps.GetValue($tPKEY_Device_FriendlyName, $sName)

ConsoleWrite($sName & @CRLF)

$tPKEY_Audio_Endpoint_GUID = _WinAPI_PKEYFromString($sPKEY_Audio_Endpoint_GUID)

$oProps.GetValue($tPKEY_Audio_Endpoint_GUID, $sGuid)

ConsoleWrite($sGuid & @CRLF)

 

Edited by Bilgus

Share this post


Link to post
Share on other sites

Thanks Bilgus

Sorry for the delay, it turned out I required the Instance ID rather than the Guid, was attempting to get this when I found another post by Trancexx which included the instance id and I was able to make a few adjustments to return the instance Id, Type (Microphone or Playback) and the name. (see code below)

nb: I tried to figure out how to use the ERoles to determine the type but reverted to using the registry as not very familiar with converting C++ into AutoIt code.

Thanks again.

#include <Array.au3>
#include <WinAPI.au3>
#include <Constants.au3>

Global Const $sCLSID_MMDeviceEnumerator = "{BCDE0395-E52F-467C-8E3D-C4579291692E}"
Global Const $sIID_IMMDeviceEnumerator = "{A95664D2-9614-4F35-A746-DE8DB63617E6}"

Global Const $tagIMMDeviceEnumerator = "EnumAudioEndpoints hresult(dword;dword;ptr*);" & _
    "GetDefaultAudioEndpoint hresult(dword;dword;ptr*);" & _
    "GetDevice hresult(wstr;ptr*);" & _
    "RegisterEndpointNotificationCallback hresult(ptr);" & _
    "UnregisterEndpointNotificationCallback hresult(ptr);"

Global Const $sCLSID_CPolicyConfigClient = "{870af99c-171d-4f9e-af0d-e63df40c2bc9}"
Global Const $sIID_IPolicyConfig = "{f8679f50-850a-41cf-9c72-430f290290c8}"

Global Const $tagIPolicyConfig = "GetMixFormat hresult(wstr;ptr*);" & _
    "GetDeviceFormat hresult(wstr;int;ptr*);" & _
    "ResetDeviceFormat hresult(wstr);" & _
    "SetDeviceFormat hresult(wstr;ptr;ptr);" & _
    "GetProcessingPeriod hresult(wstr;int;int64*;int64*);" & _
    "SetProcessingPeriod hresult(wstr;int64*);" & _
    "GetShareMode hresult(wstr;ptr);" & _
    "SetShareMode hresult(wstr;ptr);" & _
    "GetPropertyValue hresult(wstr;struct;variant*);" & _
    "SetPropertyValue hresult(wstr;struct;variant*);" & _
    "SetDefaultEndpoint hresult(wstr;int);" & _
    "SetEndpointVisibility hresult(wstr;int);"

Global Const $IID_IMMDevice = "{D666063F-1587-4E43-81F1-B948E807363F}"
Global Const $tagIMMDevice = "Activate hresult(ptr;dword;variant*;ptr*);" & _
    "OpenPropertyStore hresult(dword;ptr*);" & _
    "GetId hresult(ptr*);" & _
    "GetState hresult(dword*);"

Global Const $IID_IMMDeviceCollection = "{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}"
Global Const $tagIMMDeviceCollection = "GetCount hresult(uint*);" & _
    "Item hresult(uint;ptr*)"

Global Const $IID_IPropertyStore = "{886d8eeb-8cf2-4446-8d02-cdba1dbdcf99}"
Global Const $tagIPropertyStore = "GetCount hresult(dword*);" & _
    "GetAt hresult(dword;ptr*);" & _
    "GetValue hresult(ptr;variant*);" & _
    "SetValue hresult(ptr;variant);" & _
    "Commit hresult();"

Global Const $sPKEY_Device_FriendlyName = "{a45c254e-df1c-4efd-8020-67d146a850e0} 14"

Global Const $STGM_READ = 0
Global Const $DEVICE_STATE_ACTIVE = 0x00000001

Global Const $eRender = 0
Global Const $eCapture = 1
Global Const $eAll = 2
Global Const $EDataFlow_enum_count = 3

Global Const $eConsole = 0
Global Const $eMultimedia = 1
Global Const $eCommunications = 2
Global Const $ERole_enum_count = 3
;==========================================================
Global $aArray = _EnumerateDevices()
_ArrayDisplay($aArray)


Func _EnumerateDevices()
    ;~ Error monitoring
    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
        #forceref $oErrorHandler

;~ Registry Key for Audio Devices
    Local $sRegAudio = @OSArch = "x64" ? "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio" : "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\MMDevices\Audio"

    ;~ Create MMDeviceEnumerator object
    Local $oEnumerator = ObjCreateInterface($sCLSID_MMDeviceEnumerator, $sIID_IMMDeviceEnumerator, $tagIMMDeviceEnumerator)

    ;~ Get collection out of it
    Local $pCollection
    $oEnumerator.EnumAudioEndpoints($eAll, $DEVICE_STATE_ACTIVE, $pCollection)
    ;~ Turn it into object
    Local $oCollection = ObjCreateInterface($pCollection, $IID_IMMDeviceCollection, $tagIMMDeviceCollection)

    ;~ Check the number of devices in collection
    Local $iCount
    $oCollection.GetCount($iCount)

    ;~ Array for out
    Local $aArray[$iCount][4]
    Local $pEndpoint, $oEndpoint
    Local $pID, $sId, $pProps, $oProps
    Local $sName
    Local $tPKEY_Device_FriendlyName = _WinAPI_PKEYFromString($sPKEY_Device_FriendlyName)

    ;~ Actual enumeration
    For $i = 0 To $iCount - 1
    ;~ Item at "i" index is audio endpoint device
        $oCollection.Item($i, $pEndpoint)
        $oEndpoint = ObjCreateInterface($pEndpoint, $IID_IMMDevice, $tagIMMDevice)

    ;~ Collect ID
        $oEndpoint.GetId($pID)
        $sId = DllStructGetData(DllStructCreate("wchar ID[" & _WinAPI_PtrStringLenW($pID) & "]", $pID), "ID")
        _WinAPI_CoTaskMemFree($pID)
        $aArray[$i][2] = $sId

    ;~ Detect Instance ID is Microphone(capture) or Playback(render)
        $aGuid = StringSplit($sId, ".")
        $aArray[$i][1] = $aGuid[$aGuid[0]]
        $aArray[$i][0] = RegRead($sRegAudio & "\Capture\" & $aGuid[$aGuid[0]], "DeviceState") >= 1 ? "Microphone" : ""
        If $aArray[$i][0] = "" Then $aArray[$i][0] = RegRead($sRegAudio & "\Render\" & $aGuid[$aGuid[0]], "DeviceState") >= 1 ? "Playback" : ""

    ;~ PropertyStore stores properties, lol
        $oEndpoint.OpenPropertyStore($STGM_READ, $pProps)
        $oProps = ObjCreateInterface($pProps, $IID_IPropertyStore, $tagIPropertyStore)

    ;~ Collect FriendlyName property
        $sName = 0
        $oProps.GetValue(DllStructGetPtr($tPKEY_Device_FriendlyName), $sName)
        $aArray[$i][3] = $sName
    Next
    Return $aArray
EndFunc ;==>_EnumerateDevices

Func _SwitchToDevice($sId)
    Local $oPolicyConfig = ObjCreateInterface($sCLSID_CPolicyConfigClient, $sIID_IPolicyConfig, $tagIPolicyConfig)
    Local $hResult = $oPolicyConfig.SetDefaultEndpoint($sId, $eConsole)
    If $hResult = $S_OK Then $hResult = $oPolicyConfig.SetDefaultEndpoint($sId, $eCommunications)
    Return $hResult = $S_OK
EndFunc ;==>_SwitchToDevice


Func _WinAPI_PKEYFromString($sPKEY, $pID = Default)
    Local $tPKEY = DllStructCreate("byte GUID[16]; dword PID;")
    DllCall("propsys.dll", "long", "PSPropertyKeyFromString", "wstr", $sPKEY, "ptr", DllStructGetPtr($tPKEY))
    If @error Then ; alternative for unsupported systems
        Local $tGUID = _WinAPI_GUIDFromString($sPKEY)
        If Not @error Then
            DllStructSetData($tPKEY, "GUID", DllStructGetData(DllStructCreate("byte Data[16]", DllStructGetPtr($tGUID)), 1))
        EndIf
        DllStructSetData($tPKEY, "PID", Number(StringRegExpReplace($sPKEY, ".*?}", "")))
    EndIf
    If $pID <> Default Then DllStructSetData($tPKEY, "PID", $pID)
    Return $tPKEY
EndFunc ;==>_WinAPI_PKEYFromString

Func _WinAPI_PtrStringLenW($pString)
    Local $aCall = DllCall("kernel32.dll", "dword", "lstrlenW", "ptr", $pString)
        If @error Then Return SetError(1, 0, 0)
    Return $aCall[0]
EndFunc ;==>_WinAPI_PtrStringLenW

Func _WinAPI_CoTaskMemFree($pMem)
    DllCall("ole32.dll", "none", "CoTaskMemFree", "ptr", $pMem)
    If @error Then Return SetError(1, 0, False)
    Return True
EndFunc ;==>_WinAPI_CoTaskMemFree

Func _ErrFunc($oError)
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc ;==>_ErrFunc

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By CYCho
      zPlayer is the name I used when I introduced the early version of this palyer in my blog back in early 2009 and, therefore, has nothing to do with the mobile media player of the same name which started marketing in 2015.
      After I retired from active duty in 2002 I spent much time listening to music. First I started with CD's and LP's, then quickly moved on to mp3 files. I converted many of my CD's to mp3 and I collected many more from various sources which were freely available at the time. As the number of my mp3 files grew, I put them in folders according to their genres and my favorite classifications. I mainly used Windows Media Player to listen to them and I slowly began to dislike wmp because it had massive user interface while I just wanted to listen to music in the background while I was doing other work in the foreground, hopping between folders from time to time. It was the time I was beginning to learn AutoIt and I thought I should make my own player with AutoIt. Coming from a sales career with no experience in programming, it was not an easy task. Somehow, after about 2 years of learning and trying, I had my own audio player which worked with only hotkeys without any graphical interface. I gave it to some of my friends who were not as computer-savvy as I. They liked it but definitely wanted something to clcik with mouse. So I came up with very rude gui which took a form similar to what it is now.
      The attached source files include one au3 file, one icon file and 14 jpg files. The jpg files are used for drawing a graphical player and are fileinstalled in @DocumentsCommonDir folder. This player uses WMPlayer.OCX as its engine and supports all audio file formats supported by wmp and additional codecs installed. I would like to thank @Bilgus for kind answers to my questions and would appreciate it if anyone could review the code and give me any suggestion. This player works for me, but I don't know whether the code is presentable as an example. I am posting this here with a hope to learn much from AutoIt community.
       
      PS: 1. An error (Variable used before declaration) was reported and corrected - 02:00 hours GMT,  March 14, 2019
            2. An error in tray menu was corrected -10:00 hours GMT, March14, 2019
            3. AutoIt3Wrapper_Au3Check_Parameters definition was added at the top of the code and all ensuing errors were corrected. - 00:10 hours GMT, March 16 2019
            4. Some features were added. - 10:30 hours GMT, March 18, 2019
                a. Jumping to new play-back position in a file
                b. Support for a manually made playlist
                c. Ctrl+Alt+h hotkey to trigger a help message box
      zPlayer_20190318.zip


    • By TheSaint
      This is my latest project, which I have been working on for a few days now, so this is kind of hot off the press. However, in reality, I have been working on some element of this for years. Some of you may remember a huge project of mine (Audio DVD Producer + Chat Blog Screenshots) that I worked on a good while back? Well, this one is very much related, and very much simpler in scope. That other project by the way, has been basically stalled for a good length of time now. Not because I never finished it, but because the end result was not as great as I hoped. I may share the files for it one day. I may even start working on it again one day, though this latest project kind of makes much of it redundant for my aims.
      Anyway, this project. I have a good bunch of DTS-CDs, from same or other sources (i.e. DVD). You can read more about what a DTS-CD is here, but the short of it, is that you cannot play them on a normal CD player, as you will just get noise. Many if not most DVD or Blu-ray players can play the embedded DTS data in the otherwise empty CD tracks. Further to that, a DTS-CD is essentially a compressed PCM or WAV file for all intents and purposes ... to keep things simple. So a 6 Channel (5.1) track takes up roughly the same amount of bytes as a normal stereo CD track ... so 6 channels for the price of 2.
      Up until recently, the best device for me to play the DTS-CDs on, as CDs, is my PS3. It plays them faithfully (reader issues aside) and has nice visuals. It is also my most convenient DVD/Blu-ray player, so a heap of hassle to play on one of my regular players, and not much success with the Xbox 360 ... at least with burnt backup copies.
      DTS-CDs are also kind of old school, and been superseded by the more superior lossless DVD Audio, Super CD and now Blu-ray Audio discs. That kind of makes them rare now and essentially irreplaceable, so being a wise man, I store them safely and only play backup discs.
      Playing discs though is kind of limited, and to be honest a pain, as my PS3 spits the dummy on some days, with the reader not being what its should be ... or perhaps poorly calibrated. So for a long time now, I have been wanting to use the backup files instead. Unfortunately, while I can play them fine on my PC (foobar2000 + DTS plugin), that is not where I want to listen to them. Until recently, neither my NeoTV 550 hardware player or my Laser one, have been very good at playing the files, and the PS3 even worse with its lack of file support. Back when I first investigated all this, and tried a bunch of things, and didn't yet have the Laser (4k Android) player, I did attempt to go the FLAC route. However, I was left unsatisfied, as my NeoTV did not support CUE files and M3U playlist files are a bit of a hassle ... and no help, when I have a single album file with cue index points for each track ... which many of my DTS-CD rips were ... especially for albums that have one track running into the next ... live albums too. The other issues for me with FLAC, were the artwork (album cover) and TAGS (details for each track - Title, Artist, Album, Year, etc), which I could not get to work.
      So, moving forward to recently. I played a DTS-CD on the PS3 the other day, and if there is one things I hate, it is a playing issue when I am in the midst of enjoying a nice piece of music. The PS3 is not very forgiving and just aborts play. I am not very forgiving of the PS3, so decided to investigate FLACs again. Now perhaps something has changed, since I last tried ... or I just wasn't on the ball. Anyway, to cut a long story a bit shorter, I loaded a DTS WAV file in foobar2000, and ripped it to a FLAC file. I then tried that file on my NeoTV 550 hardware player, and it played fine ... and some tags were visible, which surprised me. So I thought it was worth looking into further. I also tried the file on my Laser hardware player, with the Kodi (XBMC) Android app, but alas, while the Tags and Artwork worked well, all I got was noise ... and same for every other app I tried.
      Now don't ask me why I thought to try FLAC on its own, using the FLAC Frontend program initially, but I did ... and it recognized the tracks as 5.1. With foobar2000, I'd selected the decoder for DTS files when converting to FLAC, as I thought it was required. I hadn't at that stage used flac.exe by itself, but I decided to investigate the TAG command-line options and also noticed you could embed a picture, which I was keen as mustard to try. So I set up a BAT file and gave it a whirl.
      Now the results on my NeoTV 550 hardware player, were brilliant - Sound, Tags and Artwork were as I wanted. I decided to update Kodi at that point. Then, I tried my Laser hardware player again, but still no joy. I then did some online research and read about how to get it all working. Alas, I had mixed results. The foobar2000 ripped file worked, but the one I did with the BAT file did not. Not being keen to rip everything via foobar2000 menus, and wanting to code a quicker batch solution myself, I first attempted to see what command-line options I could use for foobar. That was a dismal failure, so I then revisited some of the programs I had used way back when with DTS WAV based files, and eventually discovered that 'valdec.exe' from the AC3Filter tools collection, gave the compatibility I needed. So I put my WAV or DTS files through that program first, then converted them to FLAC.
      Now the files played with DTS surround sound, on both my hardware players. They also play gapless, so I split album length files into separate track files, which avoids the CUE and M3U issues. That said, a joined M3U file for something like a (separate folders) double album, plays great with Kodi.
      So of course, I just had to whip up a program ... with drag and drop of course.
      And that program has steadily been growing & changing, and is where I want it now, at v1.5.
      Screenshots further below.
      REQUIRED COMPONENTS
      Most programs (if not all) can be obtained from VideoHelp, but here are some alternative sites to source them. The 'flac.exe' program is definitely required, and 'valdec.exe' if you want maximum compatibility support for a wider range of players.
      [flac.exe]
      https://xiph.org/flac/
      https://xiph.org/flac/download.html
      https://ftp.osuosl.org/pub/xiph/releases/flac/
      https://ftp.osuosl.org/pub/xiph/releases/flac/flac-1.3.1-win.zip
      [valdec.exe] [found in the AC3Filter tools collection]
      http://www.ac3filter.net/wiki/AC3Filter_tools (Info only, downloads no longer work)
      https://web.archive.org/web/*/http://www.ac3filter.net/wiki/AC3Filter_tools
      https://web.archive.org/web/20130623004920/http://www.ac3filter.net:80/wiki/Download_AC3Filter_tools
      If The Wayback Machine options fail, then go to VideoHelp (maybe go there anyway).
      https://www.videohelp.com/software/AC3-Filter/old-versions
      NOTE - The AC3Filter site has loads of information, which could help you enable other players aside from those below.
      RECOMMENDED PLAYERS
      PC = foobar2000 + DTS plugin component.
      Android Device = Kodi (XBMC) app with DTS etc enabled with passthrough.
      NOTE - foobar2000 with plugin, will play even those not processed with 'valdec.exe'. My 'NeoTV 550' hardware player does the same. My 'Laser' (Android device) with Kodi just emits noise with the FLAC files, if not processed with 'valdec.exe'.
      RECOMMENDED DTS-CD RIPPERS
      http://www.imgburn.com/
      http://www.exactaudiocopy.de/
      OTHER LINKS
      This one of mine tells you a lot more about DTS-CDs, including ripping or burning.
      https://forum.doom9.org/showthread.php?t=172484
      SCREENSHOTS
         

      P.S. I made a brilliant discovery today. Whereas in the past, with PS3 etc, I could not listen to my DTS-CDs via my Surround Sound Headphones, I now can with these files. So it is well worth playing those CDs as files, just for that benefit alone. Overall though, I have future proofed my collection.
    • By argumentum
      Today I decided to fix my problem of yelling on my headset's mic. to the point of ... coding a solution 

      As I change the headset, the mic. don't change ( and I forget to do it manually ), so I searched the form for code and came up with the solution to my need.
      #include <Debug.au3> ; for _DebugArrayDisplay() #include "SetMicForPlayback.bulk.au3" ;~ Global $g_aEnumerateAudioDevices = _EnumerateAudioDevices() ;~ Global $g_aEnumerateAudioDevicesWas = $g_aEnumerateAudioDevices ;~ _DebugArrayDisplay($g_aEnumerateAudioDevicesWas, "$g_aEnumerateAudioDevicesWas") ;~ Row |Col 0 |Col 1 |Col 2 |Col 3 |Col 4 ;~ Row 0 |Playback |{34d90035-0679-4b97-b868-ddba418b989b} |{0.0.0.00000000}.{34d90035-0679-4b97-b868-ddba418b989b}|Speakers (High Definition Audio Device) |1 ;~ Row 1 |Playback |{43d508ee-19c5-4513-bd52-e1b7ba57ee82} |{0.0.0.00000000}.{43d508ee-19c5-4513-bd52-e1b7ba57ee82}|Headset Earphone (2- Arctis Pro Wireless Chat) |0 ;~ Row 2 |Playback |{a6f69bc4-f708-4a0f-bf58-995fe9d5d221} |{0.0.0.00000000}.{a6f69bc4-f708-4a0f-bf58-995fe9d5d221}|Headset Earphone (Corsair VOID Wireless Gaming Dongle) |0 ;~ Row 3 |Microphone |{a025c7e9-3655-474f-9643-8f05f1e4d591} |{0.0.1.00000000}.{a025c7e9-3655-474f-9643-8f05f1e4d591}|Headset Microphone (2- Arctis Pro Wireless Chat) |0 ;~ Row 4 |Microphone |{f9a630d2-44e9-4db5-b115-9fe7503a2ec7} |{0.0.1.00000000}.{f9a630d2-44e9-4db5-b115-9fe7503a2ec7}|Headset Microphone (Corsair VOID Wireless Gaming Dongle) |1 ;~ _SwitchToDevice($g_aEnumerateAudioDevices[4][2]) ;~ + [1]"OnDefaultDeviceChanged", [2]"0", [3]"1", [4]"{0.0.0.00000000}.{43d508ee-19c5-4513-bd52-e1b7ba57ee82}" ;~ + [1]"OnDefaultDeviceChanged", [2]"0", [3]"1", [4]"{0.0.0.00000000}.{34d90035-0679-4b97-b868-ddba418b989b}" main() Func main() If WinExists(StringTrimRight(@ScriptName, 4) & "'s hidden window") Then Exit 0 AutoItWinSetTitle(StringTrimRight(@ScriptName, 4) & "'s hidden window") Local $n, $a, $s, $b, $i While Sleep(50) If $g_aAudioSwitched[0] And TimerDiff($g_aAudioSwitched[0]) > 500 Then ConsoleWrite('+ [1]"' & $g_aAudioSwitched[1] & '", [2]"' & $g_aAudioSwitched[2] & '", [3]"' & $g_aAudioSwitched[3] & '", [4]"' & $g_aAudioSwitched[4] & '"' & @CRLF) Switch $g_aAudioSwitched[1] Case "OnDefaultDeviceChanged" $s = "" $a = _EnumerateAudioDevices() For $n = 0 To UBound($a) - 1 If $a[$n][2] = $g_aAudioSwitched[4] Then $b = StringSplit($a[$n][3], "()", 0) If UBound($b) > 2 Then $s = $b[2] ConsoleWrite($s & @CRLF) ExitLoop EndIf Next If $s = "" Then ConsoleWrite(@TAB & $s & ' = not found ?, just 1 device ?, remote audio ?' & @CRLF) Else $i = 5 For $n = 0 To UBound($a) - 1 If $a[$n][0] = "Microphone" Then If StringInStr($a[$n][3], $s) Then ; ObjCreateInterface: "Warning: This feature is experimental." $i = ShellExecuteWait(@ScriptFullPath, "/ErrorStdOut " & $a[$n][2], @ScriptDir) Switch $i Case 3 ConsoleWrite(@TAB & $s & ": apply = True" & @CRLF) Case 4 ConsoleWrite(@TAB & $s & ": apply = False" & @CRLF) Case 1 ConsoleWrite(@TAB & $s & ": apply = Crashed" & @CRLF) Case Else ConsoleWrite(@TAB & $s & ": no clue !" & @CRLF) EndSwitch ExitLoop EndIf Else ContinueLoop EndIf Next EndIf If $i = 5 Then ConsoleWrite(@TAB & $s & ' = ..have to code a "default mic" if none associated. ( you do it, I don''t have one. )' & @CRLF) ;~ AdlibRegister("did_it_work") ; ...to have some feedback while in development, but the "Sound"("Recording" tab), shows the change on the fly. Case Else ConsoleWrite("! no code written for this event" & @CRLF) EndSwitch $g_aAudioSwitched[0] = 0 $g_aAudioSwitched[1] = "" EndIf WEnd EndFunc ;==>main Func did_it_work() AdlibUnRegister("did_it_work") Local $a = _EnumerateAudioDevices() _DebugArrayDisplay($a, "_EnumerateAudioDevices()") EndFunc ;==>did_it_work  
      SetMicForPlayback.bulk.au3 The "bulk" file has the real code, ( not mine, references are in the code )
      SetMicForPlayback.au3 this is the "main()" ( the code you can read above ).
      Works for me on Win10 v???.???.?? ( I'm not good with updates ).
      Hope it helps the next guy playing TF2 as an engineer, finding a headset close to you, to tell your team color to use the teleport that goes to the enemy base to get the intel., no one listens, you get aggravated, #%#$#@$ ....  

       
      PS: ..the above code misbehaves a lot and is left for the adventurous.
      Use the current code in the downloads section for a functional script.
    • By PuneetTewani
      #include <IE.au3>
      #include <Tesseract.au3>
      #include <MsgBoxConstants.au3>
      #include <Math.au3>
      #include <FileConstants.au3>
      #include <StringConstants.au3>
      #include <File.au3>
      #include <ScreenCapture.au3>
      #include <sound.au3>
      #Include <WinAPI.au3>
      #include <Date.au3>
       
      $OCR_Result = _TesseractScreenCapture(0,"",1,2,220,660,500,730,1)
      $OCR_Result1 = _TesseractScreenCapture(0,"",1,2,220,660,500,730,1)
      $OCR_Result2 = _TesseractScreenCapture(0,"",1,2,220,660,500,730,1)
      $OCR_Result3 = _TesseractScreenCapture(0,"",1,2,220,660,500,730,1)

      $sound = _SoundStatus("C:\ExpertAdvisorBuyAlert.wav")
      while _nowtime < 3.30 pm
          If $sound = True Then
             if $OCR_Result1 > $OCR_Result2
             
          EndIf
      EndIf
      Wend
      Trying to ocr some values on chart in real time(once per minute) and buy/sell securities on basis of alert generated in my software.
      I am struck onto few steps.
      1. On Tesseract Screen Capture indentation parameters. How can we determine the exact parameters if I just want numeric values only.
      2. The Tesseract Screen Capture generates and error Obj1 on line 185 which needs to be resolved.
      3. Sometimes lines get overlapped with values. What to do in that case.
      3. Detecting the sound as and when it approaches and then comparing the ocr values to decide on either buy or sell.
      The values that needs to be fetched are encircled.

    • By nacerbaaziz
      hello
      Hi dear, I have a question please
      I designed a function to read the content of the playlist
      I succeeded in that
      I have a problem
      For VLC player playlists
      If the path of the files in Arabic language the path is be as follows
      %D8%A3%D8%B0%D9%83%D8%A7%D8%B1%20%D9%88%D8%A3%D8%AF%D8%B9%D9%8A%D8%A9/%D8%A3%D8%B0%D9%83%D8%A7%D8%B1%20%D9%85%D9%86%D9%88%D8%B9%D8%A9/%D8%A3%D8%B0%D9%83%D8%A7%D8%B1%2003.mp3
      I did not know how to decrypt this text to be readable
      This is the function that i used

      func M3UImport($M3UFile) dim $AM3UItems local $fileOpen = FileOpen($path, bitOr($FO_OVERWRITE,$FO_CREATEPATH,$FO_ANSI)) _FileReadToArray ($fileOpen, $AM3UItems) if @error then return setError(1) local $M3UPath for $i = 1 to $AM3UItems[0] $AM3UItems[$i] = stringReplace($AM3UItems[$i], "file:///", "") $AM3UItems[$i] = stringReplace($AM3UItems[$i], "/", "\") $AM3UItems[$i] = stringReplace($AM3UItems[$i], "%20", " ") $M3UPath = _fileGetDirPath($AM3UItems[$i]) if $M3UPath = "" then $M3UPath = @WorkingDir if not StringTrimRight($M3UPath, 1) = "\" then $M3UPath &= "\" $AM3UItems[$i] = $M3UPath & $AM3UItems[$i] endIf local $ext = _GetFileExt($AM3UItems[$i]) if fileExists($AM3UItems[$i]) and not (StringInStr($FilesExt, $ext) = 0) then $aListItems[0] += 1 GUICtrlCreateListViewItem(_GetFileName($AM3UItems[$i]) & Opt("GUIDataSeparatorChar") & " : " & Opt("GUIDataSeparatorChar") & $AM3UItems[$i], $list) endIf next return "" endFunc

      I ask for your help in this work
      with my Greetings and thanks in advance
×
×
  • Create New...