Unverified Commit 98dba52c authored by Ondrej Major's avatar Ondrej Major Committed by GitHub
Browse files

Bugfix / ffmpeg input device (mic) not working on Windows (#27051)

* fix input audio device for windows.

* ffmpeg audio device Windows

* Fixes wrong input device assignment in Windows

* Fixed getting mic on Windows systems by adding _get_microphone_name() function.
parent 7d9d5cea
......@@ -52,7 +52,7 @@ def ffmpeg_microphone(
format_for_conversion: str = "f32le",
):
"""
Helper function ro read raw microphone data.
Helper function to read raw microphone data.
"""
ar = f"{sampling_rate}"
ac = "1"
......@@ -72,7 +72,7 @@ def ffmpeg_microphone(
input_ = ":0"
elif system == "Windows":
format_ = "dshow"
input_ = "default"
input_ = _get_microphone_name()
ffmpeg_command = [
"ffmpeg",
......@@ -226,3 +226,23 @@ def _ffmpeg_stream(ffmpeg_command, buflen: int):
yield raw
except FileNotFoundError as error:
raise ValueError("ffmpeg was not found but is required to stream audio files from filename") from error
def _get_microphone_name():
"""
Retrieve the microphone name in Windows .
"""
command = ["ffmpeg", "-list_devices", "true", "-f", "dshow", "-i", ""]
try:
ffmpeg_devices = subprocess.run(command, text=True, stderr=subprocess.PIPE, encoding="utf-8")
microphone_lines = [line for line in ffmpeg_devices.stderr.splitlines() if "(audio)" in line]
if microphone_lines:
microphone_name = microphone_lines[0].split('"')[1]
print(f"Using microphone: {microphone_name}")
return f"audio={microphone_name}"
except FileNotFoundError:
print("ffmpeg was not found. Please install it or make sure it is in your system PATH.")
return "default"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment