haesleinhuepf / faster-whisper-stt

Simple and basic python function for transcribing audio in realtime based on faster-whisper
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Error in utilities.py #13

Closed haesleinhuepf closed 2 months ago

haesleinhuepf commented 2 months ago

When executing "python main.py" I receive this error:

Traceback (most recent call last):
  File "C:\structure\code\faster-whisper-stt\main.py", line 22, in update_transcription
    transcribed_text = self.listener.get_transcribed_text()
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Listener' object has no attribute 'get_transcribed_text'

git-bob comment

github-actions[bot] commented 2 months ago

This message was generated by git-bob (version: 0.2.3, model: gpt-4o-2024-08-06), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

It looks like the Listener class in utilities.py is missing the get_transcribed_text method. Please ensure that Listener includes a method named get_transcribed_text that returns the expected transcribed text.

haesleinhuepf commented 2 months ago

How could that function look like? git-bob comment

github-actions[bot] commented 2 months ago

This message was generated by git-bob (version: 0.2.3, model: gpt-4o-2024-08-06), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

To resolve the issue, you can add a get_transcribed_text method within the Listener class that returns the transcribed text. Here's an example of how you might implement it:

class Listener:
    # existing methods

    def get_transcribed_text(self, audio_path):
        """Gets the transcribed text from the audio file."""
        model = WhisperModel("small", device="cpu")
        segments, _ = model.transcribe(audio_path, language="de", word_timestamps=True)
        transcription = " ".join([segment.text for segment in segments])
        return transcription

Make sure to use your get_transcribed_text method where necessary in your code to retrieve the transcription.

haesleinhuepf commented 2 months ago

Instead of creating a new WhisperModel, could we reuse the instance that exists already in the class?

git-bob comment

github-actions[bot] commented 2 months ago

This message was generated by git-bob (version: 0.2.3, model: gpt-4o-2024-08-06), an experimental AI-based assistant. It can make mistakes and has limitations. Check its messages carefully.

To reuse the existing WhisperModel instance, you can initialize it once in the Listener class's __init__ method and use it in the get_transcribed_text method. Here's how you can modify the code:

class Listener:
    def __init__(self):
        self.audio_queue = queue.Queue()
        self.sample_rate = 16000
        self.audio_data = []
        self.stream = sd.InputStream(callback=self.audio_callback, samplerate=self.sample_rate, channels=1, dtype='int16')
        self.model = WhisperModel("small", device="cpu")  # Initialize the model here

    # existing methods

    def get_transcribed_text(self, audio_path):
        """Gets the transcribed text from the audio file."""
        segments, _ = self.model.transcribe(audio_path, language="de", word_timestamps=True)
        transcription = " ".join([segment.text for segment in segments])
        return transcription

With these changes, the existing WhisperModel instance is reused for transcription. Update other methods as needed to use get_transcribed_text if required.

haesleinhuepf commented 2 months ago

git-bob implement this!