move to /rust-whisper.d with a download_models.sh
This commit is contained in:
@@ -1,320 +0,0 @@
|
||||
import speech_recognition as sr
|
||||
import time
|
||||
import threading
|
||||
import queue
|
||||
import signal
|
||||
import sys
|
||||
import os
|
||||
import requests
|
||||
import yaml
|
||||
|
||||
def log(*args):
|
||||
print(">", *args, file=sys.stderr)
|
||||
|
||||
class Piper(threading.Thread):
|
||||
def __init__(self, inq, outq):
|
||||
threading.Thread.__init__(self)
|
||||
self.inq = inq
|
||||
self.outq = outq
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
got = self.inq.get()
|
||||
if got is None:
|
||||
break
|
||||
self._run(got)
|
||||
self.outq.put(None)
|
||||
|
||||
class Manager(threading.Thread):
|
||||
def __init__(self, outq):
|
||||
threading.Thread.__init__(self)
|
||||
self.outq = outq
|
||||
inq = queue.Queue()
|
||||
def catcher(sig, frame):
|
||||
inq.put(None)
|
||||
self.inq = inq
|
||||
signal.signal(signal.SIGINT, catcher)
|
||||
|
||||
def run(self):
|
||||
log("Manager.run: start")
|
||||
self.inq.get()
|
||||
self.outq.put(None)
|
||||
log("Manager.run: stop")
|
||||
|
||||
class Reader(threading.Thread):
|
||||
def __init__(self, inq, outq):
|
||||
threading.Thread.__init__(self)
|
||||
self.name = os.environ.get("MIC_NAME", "pulse_monitor")
|
||||
if not self.name:
|
||||
for index, name in enumerate(sr.Microphone.list_microphone_names()):
|
||||
print("[{0}] Microphone with name \"{1}\" found for `Microphone(device_index={0})`".format(index, name))
|
||||
exit()
|
||||
self.inq = inq
|
||||
self.outq = outq
|
||||
|
||||
def run(self):
|
||||
log("Reader.run: start")
|
||||
try:
|
||||
idx = [
|
||||
idx for idx,v in enumerate(
|
||||
sr.Microphone.list_microphone_names(),
|
||||
) if v in self.name.split(",")
|
||||
][0]
|
||||
with sr.Microphone(device_index=idx) as mic:
|
||||
while not self.should_stop():
|
||||
try:
|
||||
self.outq.put(self._run(mic))
|
||||
except Exception as e:
|
||||
if not "timed out" in str(e):
|
||||
log("Reader.run: error:", e)
|
||||
except Exception as e:
|
||||
log("Reader.run panic:", e)
|
||||
log("microphones:", sr.Microphone.list_microphone_names())
|
||||
finally:
|
||||
self.outq.put(None)
|
||||
log("Reader.run: stop")
|
||||
|
||||
def should_stop(self):
|
||||
return not self.inq.empty()
|
||||
|
||||
def _run(self, mic):
|
||||
mic_timeout = int(os.environ.get("MIC_TIMEOUT", 5))
|
||||
r = sr.Recognizer()
|
||||
return r.listen(
|
||||
mic,
|
||||
timeout=mic_timeout,
|
||||
phrase_time_limit=mic_timeout,
|
||||
)
|
||||
|
||||
class Parser(threading.Thread):
|
||||
def __init__(self, inq, outq):
|
||||
threading.Thread.__init__(self)
|
||||
self.inq = inq
|
||||
self.outq = outq
|
||||
|
||||
def run(self):
|
||||
log("Parser.run: start")
|
||||
while True:
|
||||
try:
|
||||
clip = self.inq.get()
|
||||
backlog = self.inq.qsize()
|
||||
if backlog:
|
||||
log("Parser.run backlog", backlog)
|
||||
if clip is None:
|
||||
break
|
||||
self.outq.put(self._run(clip))
|
||||
except Exception as e:
|
||||
log("Parser.run: error:", e)
|
||||
self.outq.put(None)
|
||||
log("Parser.run: stop")
|
||||
|
||||
def _run(self, clip):
|
||||
wav = clip.get_wav_data(convert_rate=16000)
|
||||
p = "/tmp/whisper-cpp.wav"
|
||||
with open("/tmp/whisper-cpp.wav", "wb") as f:
|
||||
f.write(wav)
|
||||
proc = subprocess.run(f"MODEL=./models/ggml-{os.environ.get('MODEL','tiny.en')}.bin WAV={p} P=2 rust-whisper", capture_output=True, shell=True)
|
||||
result = proc.stdout.decode().strip()
|
||||
if os.environ.get("DEBUG", None):
|
||||
log("raw transcript:", result)
|
||||
result = result.replace(">>", "")
|
||||
result = "".join([i.split("]")[-1] for i in result.split("[")[0]])
|
||||
result = "".join([i.split(")")[-1] for i in result.split("(")[0]])
|
||||
if os.environ.get("DEBUG", None):
|
||||
log("annotation-free transcript:", result)
|
||||
return result
|
||||
#r = sr.Recognizer()
|
||||
#return r.recognize_whisper(clip, language="english", model=os.environ.get("MODEL", "small.en")) # tiny.en=32x, base.en=16x, small.en=6x, medium.en=x2
|
||||
|
||||
import subprocess
|
||||
|
||||
def load_dot_notation(v, s):
|
||||
items = s.replace("[]", ".[]").split(".")
|
||||
return _load_dot_notation(v, items)
|
||||
|
||||
def _load_dot_notation(v, items):
|
||||
for i in range(len(items)):
|
||||
k = items[i]
|
||||
if not k:
|
||||
continue
|
||||
if k == "[]":
|
||||
if isinstance(v, list):
|
||||
result = []
|
||||
for j in v:
|
||||
subresult = _load_dot_notation(j, items[i+1:])
|
||||
if isinstance(subresult, list):
|
||||
result.extend(subresult)
|
||||
else:
|
||||
result.append(subresult)
|
||||
return result
|
||||
else:
|
||||
result = []
|
||||
for j in v.values():
|
||||
subresult = _load_dot_notation(j, items[i+1:])
|
||||
if isinstance(subresult, list):
|
||||
result.extend(subresult)
|
||||
else:
|
||||
result.append(subresult)
|
||||
return result
|
||||
else:
|
||||
if isinstance(v, list):
|
||||
v = v[int(k)]
|
||||
else:
|
||||
v = v[k]
|
||||
return v
|
||||
|
||||
def test_load_dot_notation():
|
||||
for i in [
|
||||
"a" == load_dot_notation("a", "."),
|
||||
["a"] == load_dot_notation(["a"], "."),
|
||||
"b" == load_dot_notation({"a":"b"}, ".a"),
|
||||
"c" == load_dot_notation({"a":{"b":"c"}}, ".a.b"),
|
||||
"c" == load_dot_notation({"a":{"b":["c"]}}, ".a.b.0"),
|
||||
["c","d"] == load_dot_notation({"a":{"b":"c"}, "a2":{"b":"d"}}, ".[].b"),
|
||||
["c","d"] == load_dot_notation({"a":{"b":["c"], "b2":["d"]}}, ".a.[].0"),
|
||||
["c","d"] == load_dot_notation({"a":{"b":["c"], "b2":["d"]}}, ".a[].0"),
|
||||
["c","d"] == load_dot_notation(["c", "d"], "."),
|
||||
["c","d"] == load_dot_notation(["c", "d"], "[]"),
|
||||
]:
|
||||
if not i:
|
||||
raise Exception(i)
|
||||
test_load_dot_notation()
|
||||
|
||||
class Reactor(threading.Thread):
|
||||
def __init__(self, inq, outq):
|
||||
threading.Thread.__init__(self)
|
||||
self.inq = inq
|
||||
self.outq = outq
|
||||
self.load_hotwords = Reactor.new_load_hotwords()
|
||||
log(f"hotwords: {self.load_hotwords()}")
|
||||
|
||||
def new_load_hotwords():
|
||||
p = os.environ.get("HOTWORDS", None)
|
||||
if not p:
|
||||
def load_nothing():
|
||||
return []
|
||||
return load_nothing
|
||||
|
||||
try:
|
||||
if "@" in p:
|
||||
def load_hotwords_in_yaml_file():
|
||||
with open(p.split("@")[0], "r") as f:
|
||||
v = yaml.safe_load(f)
|
||||
v = load_dot_notation(v, p.split("@")[-1])
|
||||
return ["".join(i.strip().lower().split()) for i in v if i]
|
||||
load_hotwords_in_yaml_file()
|
||||
return load_hotwords_in_yaml_file
|
||||
else:
|
||||
def load_hotwords_in_file():
|
||||
with open(p, "r") as f:
|
||||
return ["".join(i.strip().lower().split()) for i in f.readlines()]
|
||||
load_hotwords_in_file()
|
||||
return load_hotwords_in_file
|
||||
except Exception as e:
|
||||
log(f"$HOTWORDS {p} is not a file: {e}")
|
||||
|
||||
hotwords = ["".join(i.lower().strip().split()) for i in p.split("\/\/")]
|
||||
log(f'$HOTWORDS: {hotwords}')
|
||||
def load_hotwords_as_literal():
|
||||
return hotwords
|
||||
return load_hotwords_as_literal
|
||||
|
||||
def run(self):
|
||||
log("Reactor.run: start")
|
||||
while True:
|
||||
text = self.inq.get()
|
||||
if text is None:
|
||||
break
|
||||
self.handle(text)
|
||||
self.outq.put(None)
|
||||
log("Reactor.run: stop")
|
||||
|
||||
def handle(self, text):
|
||||
hotwords = self.load_hotwords()
|
||||
if os.environ.get("DEBUG", None):
|
||||
log(f"seeking {hotwords} in {text}")
|
||||
if not hotwords:
|
||||
if not os.environ.get("HOTWORDS", None):
|
||||
print(text)
|
||||
else:
|
||||
log(text)
|
||||
return
|
||||
cleantext = "".join([i for i in "".join(text.lower().split()) if i.isalpha()])
|
||||
for i in hotwords:
|
||||
if i in cleantext:
|
||||
#log(f"Reactor.handle: found hotword '{i}' in '{text}' as '{cleantext}'")
|
||||
self.outq.put((i, text))
|
||||
|
||||
class Actor(threading.Thread):
|
||||
def __init__(self, inq):
|
||||
threading.Thread.__init__(self)
|
||||
self.inq = inq
|
||||
self.handle = self.handle_stderr
|
||||
if os.environ.get("STDOUT", "") == "true":
|
||||
self.handle = self.handle_stdout
|
||||
elif os.environ.get("SIGUSR2", ""):
|
||||
self.pid = int(environ["SIGUSR2"])
|
||||
self.handle = self.handle_signal
|
||||
elif os.environ.get("URL", ""):
|
||||
self.url = environ["URL"]
|
||||
self.handle = self.handle_url
|
||||
self.headers = [i.split("=")[:2] for i in os.environ.get("HEADERS", "").split("//") if i]
|
||||
self.body = os.environ.get("BODY", '{"hotword":"{{hotword}}","context":"{{context}}"}')
|
||||
log(self.headers)
|
||||
|
||||
def run(self):
|
||||
log("Actor.run: start")
|
||||
while True:
|
||||
got = self.inq.get()
|
||||
if got is None:
|
||||
break
|
||||
self.handle(got[0], got[1])
|
||||
log("Actor.run: stop")
|
||||
|
||||
def handle_stderr(self, hotword, context):
|
||||
log(f"'{hotword}' in '{context}'")
|
||||
|
||||
def handle_stdout(self, hotword, context):
|
||||
log(context)
|
||||
print(hotword)
|
||||
|
||||
def handle_signal(self, hotword, context):
|
||||
self.handle_stderr(hotword, context)
|
||||
os.kill(self.pid, signal.SIGUSR2)
|
||||
|
||||
def handle_url(self, hotword, context):
|
||||
self.handle_stderr(hotword, context)
|
||||
try:
|
||||
headers = {}
|
||||
for i in self.headers:
|
||||
key = i[0]
|
||||
value = i[1]
|
||||
value = value.replace("{{hotword}}", hotword)
|
||||
value = value.replace("{{context}}", context)
|
||||
headers[key] = value
|
||||
body = self.body
|
||||
body = body.replace("{{hotword}}", hotword)
|
||||
body = body.replace("{{context}}", context)
|
||||
if os.environ.get("DEBUG", "") :
|
||||
log("POST", self.url, headers, body)
|
||||
requests.post(self.url, headers=headers, data=body)
|
||||
except Exception as e:
|
||||
log("Actor.handle_url:", e)
|
||||
|
||||
def main():
|
||||
managerToParserQ = queue.Queue(maxsize=1)
|
||||
readerToParserQ = queue.Queue(maxsize=10)
|
||||
parserToReactorQ = queue.Queue(maxsize=10)
|
||||
reactorToActorQ = queue.Queue(maxsize=10)
|
||||
threads = [
|
||||
Manager(managerToParserQ),
|
||||
Reader(managerToParserQ, readerToParserQ),
|
||||
Parser(readerToParserQ, parserToReactorQ),
|
||||
Reactor(parserToReactorQ, reactorToActorQ),
|
||||
Actor(reactorToActorQ),
|
||||
]
|
||||
[t.start() for t in threads]
|
||||
[t.join() for t in threads]
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -5,7 +5,7 @@ if [ ! -d ./git.d/.git ]; then
|
||||
fi
|
||||
|
||||
cd ./git.d
|
||||
if [ ! -f ./samples/gb1.wav ]; then
|
||||
if [ ! -f ./samples/jfk.wav ]; then
|
||||
make samples
|
||||
fi
|
||||
if [ ! -f ./main ]; then
|
||||
@@ -20,5 +20,5 @@ fi
|
||||
if [ -n "$STREAM" ]; then
|
||||
./stream -m ./models/ggml-${MODEL:-tiny.en}.bin -t 8 --step 500 --length ${MIC_TIMEOUT:-2}000 $(test -n "$MIC_ID" && echo -c "$MIC_ID")
|
||||
else
|
||||
time ./main -m ./models/ggml-${MODEL:-tiny.en}.bin -f ./samples/gb1.wav -t 4
|
||||
time ./main -m ./models/ggml-${MODEL:-tiny.en}.bin -f ./samples/jfk.wav -t 4
|
||||
fi
|
||||
|
||||
366
whisper-cpp-2023/rust.d/Cargo.lock
generated
366
whisper-cpp-2023/rust.d/Cargo.lock
generated
@@ -1,366 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.64.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4243e6031260db77ede97ad86c27e501d646a27ab57b59a574f725d98ab1fb4"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"lazy_static",
|
||||
"lazycell",
|
||||
"log",
|
||||
"peeking_take_while",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "cexpr"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
||||
dependencies = [
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clang-sys"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"libc",
|
||||
"libloading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "lazycell"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.140"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
|
||||
|
||||
[[package]]
|
||||
name = "peeking_take_while"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d"
|
||||
dependencies = [
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.6.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
|
||||
|
||||
[[package]]
|
||||
name = "riff"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9b1a3d5f46d53f4a3478e2be4a5a5ce5108ea58b100dcd139830eae7f79a3a1"
|
||||
|
||||
[[package]]
|
||||
name = "rust-whisper"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"tokio",
|
||||
"wav",
|
||||
"whisper-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"pin-project-lite",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4"
|
||||
|
||||
[[package]]
|
||||
name = "wav"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a65e199c799848b4f997072aa4d673c034f80f40191f97fe2f0a23f410be1609"
|
||||
dependencies = [
|
||||
"riff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269"
|
||||
dependencies = [
|
||||
"either",
|
||||
"libc",
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "whisper-rs"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa7e1b9b003aa3285a0e4469219566266aa1d51ced1be38587251a4f713a1677"
|
||||
dependencies = [
|
||||
"whisper-rs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "whisper-rs-sys"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97a389dc665c7354ba6b1982850d4ba05b862907e535708ebdec92cbd9c599e8"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.45.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.42.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
|
||||
@@ -1,11 +0,0 @@
|
||||
[package]
|
||||
name = "rust-whisper"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
whisper-rs = "0.5"
|
||||
wav = "1"
|
||||
tokio = "1.27"
|
||||
@@ -1,8 +0,0 @@
|
||||
#! /bin/bash
|
||||
|
||||
#RUSTFLAGS="-Clink-args=-lstd++" \
|
||||
|
||||
export C_INCLUDE_PATH="$C_INCLUDE_PATH:$PWD/.."
|
||||
export LIBRARY_PATH="$LIBRARY_PATH:$PWD/.."
|
||||
|
||||
cargo "$@"
|
||||
@@ -1,37 +0,0 @@
|
||||
use whisper_rs::{WhisperContext, FullParams, SamplingStrategy};
|
||||
|
||||
fn main() {
|
||||
let mut ctx = WhisperContext::new(
|
||||
&std::env::var("MODEL").unwrap_or(String::from("../models/ggml-tiny.en.bin"))
|
||||
).expect("failed to load model");
|
||||
|
||||
// create a params object
|
||||
let mut params = FullParams::new(SamplingStrategy::Greedy { best_of: 0 });
|
||||
params.set_n_threads(
|
||||
std::env::var("P").unwrap_or(String::from("1")).parse::<i32>().expect("$P must be a number")
|
||||
);
|
||||
params.set_translate(false);
|
||||
params.set_language(Some("en"));
|
||||
params.set_print_special(false);
|
||||
params.set_print_progress(false);
|
||||
params.set_print_realtime(false);
|
||||
params.set_print_timestamps(false);
|
||||
|
||||
let (header, data) = wav::read(&mut std::fs::File::open(
|
||||
&std::env::var("WAV").unwrap_or(String::from("../git.d/samples/jfk.wav"))
|
||||
).expect("failed to open .wav")).expect("failed to decode .wav");
|
||||
assert!(header.channel_count == 1);
|
||||
assert!(header.sampling_rate == 16000);
|
||||
let data16 = data.as_sixteen().expect("wav is not 32bit floats");
|
||||
let audio_data = &whisper_rs::convert_integer_to_float_audio(&data16);
|
||||
|
||||
ctx.full(params, &audio_data[..])
|
||||
.expect("failed to run model");
|
||||
|
||||
let num_segments = ctx.full_n_segments();
|
||||
for i in 0..num_segments {
|
||||
let segment = ctx.full_get_segment_text(i).expect("failed to get segment");
|
||||
print!("{} ", segment);
|
||||
}
|
||||
println!("");
|
||||
}
|
||||
Reference in New Issue
Block a user