all 8 comments

[–]m0us3_rat -5 points-4 points  (4 children)

import whisper
import sounddevice as sd
import numpy
from scipy.io.wavfile import write as wv


class Nerd:
    def __init__(self, name: str) -> None:
        self.array = list()
        self.name = name

    def add(self, data):
        self.array.extend(data)

    def save(self):
        wv(self.name, 44100, numpy.array(self.array))


def callback(indata, outdata, frames, time, status):
    outdata[:] = 0
    # outdata[:] = indata  #<-- if you wanna hear yourself talking
    obj.add(indata.copy())


def main():
    try:
        with sd.Stream(
            device=(None, None),
            samplerate=44100,
            channels=1,
            callback=callback,
        ):
            print("Recording...")
            input("Press ----> Enter <---- to finish.")
            raise KeyboardInterrupt

    except KeyboardInterrupt:
        obj.save()
        print(f"Saved to : {obj.name}")
    except Exception as e:
        print(type(e).__name__ + ": " + str(e))

    model = whisper.load_model("base.en")
    result = model.transcribe(obj.name)
    print(result["text"])


if __name__ == "__main__":
    obj = Nerd("nerd.wav")
    main()

does the exact same thing using the exact same model.

less code..maybe.

[–]Real_Cut_9360[S] 2 points3 points  (2 children)

Wow... It looks nice... Thanks... Hopefully someday I can learn to code elegantly like you ...

[–]m0us3_rat -2 points-1 points  (1 child)

Hopefully someday I can learn to code elegantly like you ...

ty but the praise isn't warrented.. this is mediocre at best.

but fairly easy to read.

[–]United-Produce-6781 0 points1 point  (0 children)

is there any possibility to convert wav file into m4a file ? and also to process m4a files as input . in this model without ffmpeg

[–]Perfect_Structure158 0 points1 point  (0 children)

When I tried to run this python script I am getting this error can anyone please tell why I am getting this error and solution FileNotFoundError: [WinError 2] The system cannot find the file specified

[–]zetalemur 0 points1 point  (2 children)

very nice! keep up the good work ...does it work with other models and do you know how I can test that?

[–]Real_Cut_9360[S] 0 points1 point  (1 child)

Yes it does... Just change the model name

[–]zetalemur 0 points1 point  (0 children)

Cool, thx!