Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 263 for command: open speech.mpeg #472

Closed
1 task done
MoreTore opened this issue Apr 8, 2023 · 3 comments
Closed
1 task done

Error 263 for command: open speech.mpeg #472

MoreTore opened this issue Apr 8, 2023 · 3 comments

Comments

@MoreTore
Copy link

MoreTore commented Apr 8, 2023

Duplicates

  • I have searched the existing issues

Steps to reproduce 🕹

It seems that trying to call say_text() twice will cause the issue.
Running on Windows 11.
Python 3.10.10
PS D:\Projects\Auto-GPT> python scripts/main.py --speak --gpt3only

import os
from playsound import playsound
import requests
from config import Config
cfg = Config()
import gtts


# TODO: Nicer names for these ids
voices = ["ErXwobaYiN019PkySvjV", "EXAVITQu4vr4xnSDxMaL"]

tts_headers = {
    "Content-Type": "application/json",
    "xi-api-key": cfg.elevenlabs_api_key
}

def eleven_labs_speech(text, voice_index=0):
    tts_url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}".format(
        voice_id=voices[voice_index])
    formatted_message = {"text": text}
    response = requests.post(
        tts_url, headers=tts_headers, json=formatted_message)

    if response.status_code == 200:
        with open("speech.mpeg", "wb") as f:
            f.write(response.content)
        playsound("speech.mpeg")
        os.remove("speech.mpeg")
        return True
    else:
        print("Request failed with status code:", response.status_code)
        print("Response content:", response.content)
        return False

def gtts_speech(text):
    tts = gtts.gTTS(text)
    tts.save("speech.mp3")
    playsound("speech.mp3")
    os.remove("speech.mp3")

def say_text(text, voice_index=0):
    if not cfg.elevenlabs_api_key:
        gtts_speech(text)
    else:
        success = eleven_labs_speech(text, voice_index)
        if not success:
            gtts_speech(text)

if __name__ == "__main__":
    say_text("Hello, this")
    say_text("Hello, this")

Current behavior 😯

When using speak mode, it works for a random number of times but then eventually leads to this error.

Speak Mode: ENABLED
GPT3.5 Only Mode: ENABLED
Welcome to Auto-GPT! Enter the name of your AI and its role below. Entering nothing will load defaults.
Name your AI: For example, 'Entrepreneur-GPT'
AI Name: Realestate-GPT

Error 263 for command:
    open speech.mpeg
The specified device is not open or is not recognized by MCI.

Error 263 for command:
    close speech.mpeg
The specified device is not open or is not recognized by MCI.

Failed to close the file: speech.mpeg
Traceback (most recent call last):
File "D:\Projects\Auto-GPT\scripts\main.py", line 275, in
prompt = construct_prompt()
File "D:\Projects\Auto-GPT\scripts\main.py", line 178, in construct_prompt
config = prompt_user()
File "D:\Projects\Auto-GPT\scripts\main.py", line 207, in prompt_user
print_to_console(
File "D:\Projects\Auto-GPT\scripts\main.py", line 30, in print_to_console
speak.say_text(f"{title}. {content}")
File "D:\Projects\Auto-GPT\scripts\speak.py", line 45, in say_text
success = eleven_labs_speech(text, voice_index)
File "D:\Projects\Auto-GPT\scripts\speak.py", line 27, in eleven_labs_speech
playsound("speech.mpeg")
File "C:\Users\faste\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\playsound.py", line 72, in _playsoundWin
winCommand(u'open {}'.format(sound))
File "C:\Users\faste\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\playsound.py", line 64, in winCommand
raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException:
Error 263 for command:
open speech.mpeg
The specified device is not open or is not recognized by MCI.

Expected behavior 🤔

it should speak

Your prompt 📝

# Paste your prompt here
@MoreTore
Copy link
Author

MoreTore commented Apr 8, 2023

GPT4 says

The error you're encountering might be caused by the playsound library not releasing the file properly after playing the sound. To resolve this issue, you can use a different method to play the sound, such as using the pydub library with the simpleaudio playback module.

@MoreTore
Copy link
Author

MoreTore commented Apr 8, 2023

Solution!

pip uninstall playsound
pip install playsound==1.2.2

@ThirdDemented
Copy link

+1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants