mirror of
https://github.com/shirayu/whispering.git
synced 2024-06-02 21:39:28 +00:00
Add --mic option
This commit is contained in:
parent
248d379078
commit
4896570e3d
|
@ -3,6 +3,7 @@
|
||||||
import argparse
|
import argparse
|
||||||
import queue
|
import queue
|
||||||
from logging import INFO, getLogger
|
from logging import INFO, getLogger
|
||||||
|
from typing import Optional, Union
|
||||||
|
|
||||||
import sounddevice as sd
|
import sounddevice as sd
|
||||||
import torch
|
import torch
|
||||||
|
@ -16,8 +17,11 @@ from whisper_streaming.transcriber import WhisperStreamingTranscriber
|
||||||
logger = getLogger(__name__)
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def transcribe_from_mic(config: WhisperConfig) -> None:
|
def transcribe_from_mic(
|
||||||
sd_device = None
|
*,
|
||||||
|
config: WhisperConfig,
|
||||||
|
sd_device: Optional[Union[int, str]],
|
||||||
|
) -> None:
|
||||||
wsp = WhisperStreamingTranscriber(config=config)
|
wsp = WhisperStreamingTranscriber(config=config)
|
||||||
q = queue.Queue()
|
q = queue.Queue()
|
||||||
|
|
||||||
|
@ -69,6 +73,9 @@ def get_opts() -> argparse.Namespace:
|
||||||
type=int,
|
type=int,
|
||||||
default=5,
|
default=5,
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--mic",
|
||||||
|
)
|
||||||
|
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
@ -78,13 +85,21 @@ def main() -> None:
|
||||||
logger.setLevel(INFO)
|
logger.setLevel(INFO)
|
||||||
if opts.beam_size <= 0:
|
if opts.beam_size <= 0:
|
||||||
opts.beam_size = None
|
opts.beam_size = None
|
||||||
|
try:
|
||||||
|
opts.mic = int(opts.mic)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
config = WhisperConfig(
|
config = WhisperConfig(
|
||||||
model_name=opts.model,
|
model_name=opts.model,
|
||||||
language=opts.language,
|
language=opts.language,
|
||||||
device=opts.device,
|
device=opts.device,
|
||||||
beam_size=opts.beam_size,
|
beam_size=opts.beam_size,
|
||||||
)
|
)
|
||||||
transcribe_from_mic(config=config)
|
transcribe_from_mic(
|
||||||
|
config=config,
|
||||||
|
sd_device=opts.mic,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue