vivekuppal / transcribe

Transcribe is a real time transcription, conversation, Language learning platform. It provides live transcripts from microphone and speaker. It generates a suggested conversation response using OpenAI's GPT API. It will read out the responses, simulating a real live conversation in English or another language.
https://abhinavuppal1.github.io/
MIT License
182 stars 42 forks source link

Encountered a problem and could not open main.py #70

Closed jinnnnnnnnnsd closed 1 year ago

jinnnnnnnnnsd commented 1 year ago

[INFO] Listening to sound from Microphone: #24 - Microphone Array (Technologie Intel® Smart Sound) [INFO] Listening to sound from Speaker: #22 - Enceintes (2- Realtek(R) Audio) [Loopback] [INFO] Adjusting for ambient noise from Default Speaker. Please play sound from Default Speaker... Traceback (most recent call last): File "C:\Users\jin.DESKTOP-VD7S25E\transcribe\AudioRecorder.py", line 122, in adjust_for_noise self.recorder.adjust_for_ambient_noise(self.source) File "C:\Users\jin.DESKTOP-VD7S25E\transcribe\custom_speech_recognition__init__.py", line 437, in adjust_for_ambient_noise assert source.stream is not None, "Audio source must be entered before adjusting, see documentation for AudioSource; are you using source outside of a with statement?" AssertionError: Audio source must be entered before adjusting, see documentation for AudioSource; are you using source outside of a with statement?

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "main.py", line 211, in main() File "main.py", line 87, in main global_vars = GlobalVars.TranscriptionGlobals() File "C:\Users\jin.DESKTOP-VD7S25E\transcribe\GlobalVars.py", line 44, in init self.speaker_audio_recorder = AudioRecorder.SpeakerRecorder() File "C:\Users\jin.DESKTOP-VD7S25E\transcribe\AudioRecorder.py", line 208, in init self.adjust_for_noise("Default Speaker", File "C:\Users\jin.DESKTOP-VD7S25E\transcribe\AudioRecorder.py", line 122, in adjust_for_noise self.recorder.adjust_for_ambient_noise(self.source) File "C:\Users\jin.DESKTOP-VD7S25E\transcribe\custom_speech_recognition__init.py", line 232, in exit__ self.stream.close() AttributeError: 'NoneType' object has no attribute 'close'

This problem occurs when opening main.py. How to solve it? Please

vivekuppal commented 1 year ago

Assuming you are attempting this on Windows. We do not support Mac as of yet.

could you please share the output of the following command pip list

jinnnnnnnnnsd commented 1 year ago

Assuming you are attempting this on Windows. We do not support Mac as of yet.

could you please share the output of the following command pip list

Package Version


absl-py 0.14.1 aiohttp 3.8.5 aiosignal 1.3.1 alabaster 0.7.12 anaconda-client 1.7.2 anaconda-navigator 2.0.4 anaconda-project 0.8.3 apyori 1.1.2 argh 0.26.2 argon2-cffi 20.1.0 asgiref 3.5.2 asn1crypto 1.4.0 astroid 2.4.2 astropy 4.0.2 astunparse 1.6.3 async-generator 1.10 async-timeout 4.0.3 atomicwrites 1.4.0 attrs 20.3.0 autopep8 1.5.4 Babel 2.8.1 backcall 0.2.0 backports.functools-lru-cache 1.6.1 backports.shutil-get-terminal-size 1.0.0 backports.tempfile 1.0 backports.weakref 1.0.post1 backports.zoneinfo 0.2.1 bcrypt 3.2.0 beautifulsoup4 4.9.3 bitarray 1.6.1 bkcharts 0.2 bleach 3.2.1 bokeh 2.2.3 boto 2.49.0 Bottleneck 1.3.2 brotlipy 0.7.0 bs4 0.0.1 cachetools 4.2.4 certifi 2023.5.7 cffi 1.14.3 chardet 3.0.4 charset-normalizer 3.2.0 chinese-calendar 1.8.0 clang 5.0 click 7.1.2 cloudpickle 1.6.0 clyent 1.2.2 colorama 0.4.4 comtypes 1.1.7 conda 4.12.0 conda-build 3.20.5 conda-content-trust 0+unknown conda-package-handling 1.7.2 conda-repo-cli 1.0.4 conda-token 0.3.0 conda-verify 3.4.2 contextlib2 0.6.0.post1 cryptography 3.1.1 customtkinter 5.2.0 cycler 0.10.0 Cython 0.29.21 cytoolz 0.11.0 darkdetect 0.8.0 dask 2.30.0 decorator 4.4.2 defusedxml 0.6.0 diff-match-patch 20200713 distributed 2.30.1 Django 4.1.4 djangorestframework 3.14.0 docutils 0.16 entrypoints 0.3 et-xmlfile 1.0.1 fastcache 1.1.0 filelock 3.0.12 flake8 3.8.4 Flask 1.1.2 flatbuffers 2.0 frozenlist 1.4.0 fsspec 0.8.3 future 0.18.2 gast 0.4.0 gevent 20.9.0 glob2 0.7 gmpy2 2.1.2 google-auth 2.3.0 google-auth-oauthlib 0.4.6 google-pasta 0.2.0 greenlet 0.4.17 grpcio 1.41.0 gTTS 2.3.2 h5py 2.10.0 HeapDict 1.0.1 html5lib 1.1 idna 2.10 imageio 2.9.0 imagesize 1.2.0 importlib-metadata 2.0.0 iniconfig 1.1.1 intervaltree 3.1.0 ipykernel 5.3.4 ipython 7.19.0 ipython-genutils 0.2.0 ipywidgets 7.5.1 isort 5.6.4 itsdangerous 1.1.0 jdcal 1.4.1 jedi 0.17.1 jieba 0.42.1 Jinja2 2.11.2 joblib 0.17.0 json5 0.9.5 jsonschema 3.2.0 jupyter 1.0.0 jupyter-client 6.1.7 jupyter-console 6.2.0 jupyter-core 4.6.3 jupyterlab 2.2.6 jupyterlab-pygments 0.1.2 jupyterlab-server 1.2.0 keras-nightly 2.8.0.dev2021101307 Keras-Preprocessing 1.1.2 keyring 21.4.0 kiwisolver 1.3.0 lazy-object-proxy 1.4.3 libarchive-c 2.9 libclang 12.0.0 llvmlite 0.34.0 locket 0.2.0 lxml 4.6.1 Markdown 3.3.4 MarkupSafe 1.1.1 matplotlib 3.3.2 mccabe 0.6.1 menuinst 1.4.16 mistune 0.8.4 mkl-fft 1.2.0 mkl-random 1.1.1 mkl-service 2.3.0 mock 4.0.2 more-itertools 8.6.0 MouseInfo 0.1.3 mpmath 1.1.0 msgpack 1.0.0 multidict 6.0.4 multipledispatch 0.6.0 MyQR 2.3.1 navigator-updater 0.2.1 nbclient 0.5.1 nbconvert 6.0.7 nbformat 5.0.8 nest-asyncio 1.4.2 networkx 2.5 nltk 3.5 nose 1.3.7 notebook 6.1.4 numba 0.51.2 numexpr 2.7.1 numpy 1.19.2 numpydoc 1.1.0 oauthlib 3.1.1 olefile 0.46 openai 0.28.0 openai-whisper 20230314 opencv-python 4.6.0.66 openpyxl 3.0.5 opt-einsum 3.3.0 packaging 20.4 pandas 1.1.3 pandocfilters 1.4.3 paramiko 2.7.2 parso 0.7.0 partd 1.1.0 path 15.0.0 pathlib2 2.3.5 pathtools 0.1.2 patsy 0.5.1 pep8 1.7.1 pexpect 4.8.0 pickleshare 0.7.5 Pillow 8.0.1 pip 20.2.4 pkginfo 1.6.1 playsound 1.3.0 pluggy 0.13.1 ply 3.11 prettytable 3.2.0 prometheus-client 0.8.0 prompt-toolkit 3.0.8 protobuf 3.18.1 psutil 5.7.2 py 1.9.0 pyasn1 0.4.8 pyasn1-modules 0.2.8 PyAudioWPatch 0.2.12.6 PyAutoGUI 0.9.53 pycodestyle 2.6.0 pycosat 0.6.3 pycparser 2.20 pycurl 7.43.0.6 pydocstyle 5.1.1 pyecharts 1.8.1 pyflakes 2.2.0 PyGetWindow 0.0.9 Pygments 2.7.2 pylint 2.6.0 PyMsgBox 1.0.9 PyMySQL 1.0.2 PyNaCl 1.4.0 pyodbc 4.0.0-unsupported pyOpenSSL 19.1.0 pyparsing 2.4.7 pyperclip 1.8.2 pyreadline 2.1 PyRect 0.2.0 pyrsistent 0.17.3 PyScreeze 0.1.28 PySocks 1.7.1 pytest 0.0.0 python-dateutil 2.8.1 python-jsonrpc-server 0.4.0 python-language-server 0.35.1 python-pptx 0.6.21 pytweening 1.0.4 pytz 2020.1 PyWavelets 1.1.1 pywin32 227 pywin32-ctypes 0.2.0 pywinpty 0.5.7 PyYAML 5.3.1 pyzmq 19.0.2 QDarkStyle 2.8.1 QtAwesome 1.0.1 qtconsole 4.7.7 QtPy 1.9.0 regex 2023.8.8 requests 2.31.0 requests-oauthlib 1.3.0 rope 0.18.0 rsa 4.7.2 Rtree 0.9.4 ruamel-yaml 0.15.87 scikit-image 0.17.2 scikit-learn 0.23.2 scikit-posthocs 0.7.0 scipy 1.5.2 seaborn 0.11.0 Send2Trash 1.5.0 setuptools 50.3.1.post20201107 simplegeneric 0.8.1 simplejson 3.17.6 singledispatch 3.4.0.3 sip 4.19.13 six 1.15.0 snowballstemmer 2.0.0 sortedcollections 1.2.1 sortedcontainers 2.2.2 soundfile 0.12.1 soupsieve 2.0.1 Sphinx 3.2.1 sphinxcontrib-applehelp 1.0.2 sphinxcontrib-devhelp 1.0.2 sphinxcontrib-htmlhelp 1.0.3 sphinxcontrib-jsmath 1.0.1 sphinxcontrib-qthelp 1.0.3 sphinxcontrib-serializinghtml 1.1.4 sphinxcontrib-websupport 1.2.4 spyder 4.1.5 spyder-kernels 1.9.4 SQLAlchemy 1.3.20 sqlparse 0.4.3 statsmodels 0.12.0 sympy 1.6.2 tables 3.6.1 tb-nightly 2.7.0a20211013 tblib 1.7.0 tensorboard-data-server 0.6.1 tensorboard-plugin-wit 1.8.0 tensorflow-estimator 2.6.0 tensorflow-io-gcs-filesystem 0.21.0 termcolor 1.1.0 terminado 0.9.1 testpath 0.4.4 tf-estimator-nightly 2.8.0.dev2021101308 tf-nightly 2.8.0.dev20211011 threadpoolctl 2.1.0 tifffile 2020.10.1 tiktoken 0.3.3 toml 0.10.1 toolz 0.11.1 torch 2.0.1 tornado 6.0.4 tqdm 4.50.2 traitlets 5.0.5 typing-extensions 3.7.4.3 tzdata 2022.7 ujson 4.0.1 unicodecsv 0.14.1 urllib3 1.25.11 watchdog 0.10.3 wcwidth 0.2.5 webencodings 0.5.1 Werkzeug 1.0.1 wheel 0.35.1 widgetsnbextension 3.5.1 win-inet-pton 1.1.0 win-unicode-console 0.5 wincertstore 0.2 wrapt 1.12.1 xlrd 1.2.0 XlsxWriter 1.3.7 xlwings 0.20.8 xlwt 1.3.0 xmltodict 0.12.0 yapf 0.30.0 yarl 1.9.2 zict 2.0.0 zipp 3.4.0 zope.event 4.5.0 zope.interface 5.1.2

Of course, it's all here

vivekuppal commented 1 year ago

The issue you are encountering is in the file custom_speech_recognition\__init__.py

in the class

class Microphone(AudioSource):

in the method

    def __enter__(self):
        assert self.stream is None, "This audio source is already inside a context manager"
        self.audio = self.pyaudio_module.PyAudio()

        try:
            if self.speaker:
                p = self.audio
                self.stream = Microphone.MicrophoneStream(
                    p.open(
                        input_device_index=self.device_index,
                        channels=self.channels,
                        format=self.format,
                        rate=self.SAMPLE_RATE,
                        frames_per_buffer=self.CHUNK,
                        input=True
                    )
                )
            else:
                self.stream = Microphone.MicrophoneStream(
                    self.audio.open(
                        input_device_index=self.device_index, channels=1, format=self.format,
                        rate=self.SAMPLE_RATE, frames_per_buffer=self.CHUNK, input=True,
                    )
                )
        except Exception:
            self.audio.terminate()
        return self

An exception is being thrown in p.open method. You would want to capture and print the details of the exception to further understand the root cause of the issue at hand.

vivekuppal commented 1 year ago

We would be glad to help remediate the issue with more info. At the moment it seems like it is an environmental issue. Please re-open with more info if you need help.

876720687 commented 6 months ago

the current class 'Microphone(AudioSource)' and the function ‘enter’ is like below, what should i do to solve this error? :

libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile [INFO] Adjusting for ambient noise from Default Mic. Please make some noise from the Default Mic... Failed to open microphone stream: [Errno -9996] Invalid input device (no default output device) Traceback (most recent call last): File "D:\code\ecoute\AudioRecorder.py", line 24, in adjust_for_noise self.recorder.adjust_for_ambient_noise(self.source) File "D:\code\ecoute\custom_speech_recognition__init__.py", line 400, in adjust_for_ambient_noise assert source.stream is not None, "Audio source must be entered before adjusting, see documentation for AudioSource; are you using source outside of a with statement?" AssertionError: Audio source must be entered before adjusting, see documentation for AudioSource; are you using source outside of a with statement?

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "main.py", line 128, in main() File "main.py", line 80, in main user_audio_recorder = AudioRecorder.DefaultMicRecorder() File "D:\code\ecoute\AudioRecorder.py", line 37, in init self.adjust_for_noise("Default Mic", "Please make some noise from the Default Mic...") File "D:\code\ecoute\AudioRecorder.py", line 24, in adjust_for_noise self.recorder.adjust_for_ambient_noise(self.source) File "D:\code\ecoute\custom_speech_recognition__init.py", line 206, in exit__ self.stream.close() AttributeError: 'NoneType' object has no attribute 'close'

def __enter__(self):
    assert self.stream is None, "This audio source is already inside a context manager"
    try:
        # attempt to read the file as WAV
        self.audio_reader = wave.open(self.filename_or_fileobject, "rb")
        self.little_endian = True  # RIFF WAV is a little-endian format (most ``audioop`` operations assume that the frames are stored in little-endian form)
    except (wave.Error, EOFError):
        try:
            # attempt to read the file as AIFF
            self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")
            self.little_endian = False  # AIFF is a big-endian format
        except (aifc.Error, EOFError):
            # attempt to read the file as FLAC
            if hasattr(self.filename_or_fileobject, "read"):
                flac_data = self.filename_or_fileobject.read()
            else:
                with open(self.filename_or_fileobject, "rb") as f: flac_data = f.read()

            # run the FLAC converter with the FLAC data to get the AIFF data
            flac_converter = get_flac_converter()
            if os.name == "nt":  # on Windows, specify that the process is to be started without showing a console window
                startup_info = subprocess.STARTUPINFO()
                startup_info.dwFlags |= subprocess.STARTF_USESHOWWINDOW  # specify that the wShowWindow field of `startup_info` contains a value
                startup_info.wShowWindow = subprocess.SW_HIDE  # specify that the console window should be hidden
            else:
                startup_info = None  # default startupinfo
            process = subprocess.Popen([
                flac_converter,
                "--stdout", "--totally-silent",  # put the resulting AIFF file in stdout, and make sure it's not mixed with any program output
                "--decode", "--force-aiff-format",  # decode the FLAC file into an AIFF file
                "-",  # the input FLAC file contents will be given in stdin
            ], stdin=subprocess.PIPE, stdout=subprocess.PIPE, startupinfo=startup_info)
            aiff_data, _ = process.communicate(flac_data)
            aiff_file = io.BytesIO(aiff_data)
            try:
                self.audio_reader = aifc.open(aiff_file, "rb")
            except (aifc.Error, EOFError):
                raise ValueError("Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format")
            self.little_endian = False  # AIFF is a big-endian format
    assert 1 <= self.audio_reader.getnchannels() <= 2, "Audio must be mono or stereo"
    self.SAMPLE_WIDTH = self.audio_reader.getsampwidth()

    # 24-bit audio needs some special handling for old Python versions (workaround for https://bugs.python.org/issue12866)
    samples_24_bit_pretending_to_be_32_bit = False
    if self.SAMPLE_WIDTH == 3:  # 24-bit audio
        try: audioop.bias(b"", self.SAMPLE_WIDTH, 0)  # test whether this sample width is supported (for example, ``audioop`` in Python 3.3 and below don't support sample width 3, while Python 3.4+ do)
        except audioop.error:  # this version of audioop doesn't support 24-bit audio (probably Python 3.3 or less)
            samples_24_bit_pretending_to_be_32_bit = True  # while the ``AudioFile`` instance will outwardly appear to be 32-bit, it will actually internally be 24-bit
            self.SAMPLE_WIDTH = 4  # the ``AudioFile`` instance should present itself as a 32-bit stream now, since we'll be converting into 32-bit on the fly when reading

    self.SAMPLE_RATE = self.audio_reader.getframerate()
    self.CHUNK = 4096
    self.FRAME_COUNT = self.audio_reader.getnframes()
    self.DURATION = self.FRAME_COUNT / float(self.SAMPLE_RATE)
    self.stream = AudioFile.AudioFileStream(self.audio_reader, self.little_endian, samples_24_bit_pretending_to_be_32_bit)
    return self
vivekuppal commented 6 months ago

Add the complete source code to a PR and add link to PR here