Bugfix / ffmpeg input device (mic) not working on Windows
Author: Teapack1
Pull request: yes

# What does this PR do?
According to issue #25183 and personal experience, the `ffmpeg_microphone()` (`ffmpeg_microphone_live()`) function of the `audio_utils.py` pipeline, responsible for streaming raw microphone data, does not run propperly on Windows machines. 
It does not crash, the issue manifests by code passing once without any effect, instead of running and processing audio data continuously. 

This PR edits `pipelines/audio_utils.py`. Adds a function  `_get_microphone_name()` that fetches active microphone device name to the `ffmpeg_microphone()` function, that streams audio data from microphone. 
There are no additional dependencies used.

Sytem info:
Desktop Windows 10 Pro N 22H2
VS Code 1.83.1
Peripheral microphone

Review the PR and let me know if there shall be changes in the code or in the approach of fixing the issue, please.
@sanchit-gandhi
@Narsil



Comments:
Hello , I wanted to kindly check in on the status of this PR review. Any feedback or alternative suggestions of the microphone issue are greatly appreciated. Thank you.
@sanchit-gandhi
@Narsil

@sanchit-gandhi Im using this patch on Windows 10 desktop with external mic and Windows 10 laptop with integrated mic, active mic is always found. Only issue I found is when I connect wireless headset with a foreign name (Sluchátka s mikrofonem) - It can not read the special symbols. It might be fixed with the correct encoding though. Here is code I tested with:

```
import sys
from transformers import pipeline
from transformers.pipelines.audio_utils import ffmpeg_microphone_live
import torch

model_id = "distil-whisper/distil-medium.en"

device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32

pipe = pipeline("automatic-speech-recognition", model=model_id, device=device)
sampling_rate = pipe.feature_extractor.sampling_rate

chunk_length_s = 2  # how often returns the text
stream_chunk_s = 1  # how often the microphone is checked for new audio
mic = ffmpeg_microphone_live(
    sampling_rate=sampling_rate,
    chunk_length_s=chunk_length_s,
    stream_chunk_s=stream_chunk_s,
)
print("Start talking...")
for item in pipe(mic):
    sys.stdout.write("\033[K")
    print(item["text"], end="\r")
    if not item["partial"][0]:
        print("")
```


Which version of `ffmpeg` are you using ? The command to detect the input mic is non existent on Linux.

It's unlikely to be Windows vs Linux issue, but probably a lot more a ffmpeg version. I'm using ffmpeg 6.1 (for the absence of `-list_devices`).

Im using build 2023-11-27, that should be also v6.1.

But I'm thinking the issue is, that according to this [documentation](https://ffmpeg.org/ffmpeg-devices.html#alsa), the ffmpeg list command is different on Linux. 
> To see the list of cards currently recognized by your system check the files /proc/asound/cards and /proc/asound/devices.

Like this: `cat /proc/asound/cards`

The `-list_devices` should work on Windows and Mac. On Mac the command would be: `ffmpeg -f avfoundation -list_devices true -i `.

I have a Linux Ubuntu 22.* i can inplemement this in future commits, but I do not have Mac.

On Linux, this patch is not needed in my experience, only Windows system.

Hello all, @Narsil @sanchit-gandhi 
Are we going to merge this patch with Transformers? If you thing there is something to add, feel free to point out. 

I've been using this patch for audio live-inference, like ASR with Whisper. Without it can not use mic on Windows.

I just changed encoding for this fix to accept special symbols, so headsets named with special symbols are read correctly and assigned.

thank you
Kind Regards
Ondrej Major

@Teapack1 Thanks for looking into this issue, just ran into this problem today when completing the voice assistant project of the HF audio course. I cloned and tried your latest branch of transformers with the ffmpeg updates. For some reason it does not work, however, when I hardcode in the name of the mic as you suggested it works:

input_ = "audio=Microphone Array (Intel® Smart Sound Technology (Intel® SST))"

Do you account for the special symbol "®"?

@mmcgovern574 Thank you for the feedback !

Can you please expand on the issue you had with the patch? 

1) Did you install the Transformers branch [`'bugfix/ffmpeg_device_windows'`](https://github.com/Teapack1/transformers/tree/bugfix/ffmpeg_device_windows) ? The patch is not implemented in the `'main'` branch of my fork.

2) Did it return any error messages/logs? Or any other hint?

3) Did the issue manifested by code passing once without any effect, same as with the original ? 

If only 3) is correct, it might be the special symbols. I will have to use "alternative device names", which are ffmpeg device codes and use it for the `input_` variable. Instead of this `"Desktop Microphone (RØDE NT-USB+)"` be using this `"@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{E88C863A-F490-45C4-A1FB-4817532F6DE0}"`, where the special symbols should not be issue anymore.





@Teapack1
1. I pip installed installed Teapack1/transformers in my conda environment. 
2. No errors or message logs
3. Yes, same problem as the original code

@mmcgovern574 
It was 99% problem by my repo not being setup corrrectly. I set the correct branch as default, so now it installs the correct branch by default.