0

I am using soundplay library to play a sound with the python

However i got some error while doing so,

Here is the piece of code that should play the sound, by converting a string into audio file

import playsound # to play an audio file
import random
import os
from gtts import gTTS # google text to speech



# get string and make a audio file to be played
def speak(audio_string): 
    tts = gTTS(text=audio_string, lang='en-in') # text to speech(voice)
    r  = random.randint(1,20000000)  # random name
    audio_file = 'audio-' + str(r) + '.mp3' # audio file name
    tts.save(audio_file) # save as mp3
    playsound.playsound(audio_file) # play the audio file

    os.remove(audio_file) # remove audio file


speak("how can I help you")

Error Stack

Python 3.10.5 (tags/v3.10.5:f377153, Jun  6 2022, 16:14:13) [MSC v.1929 64 bit (AMD64)] on win32


    Error 263 for command:
        open audio-14004851.mp3
    The specified device is not open or is not recognized by MCI.

    Error 263 for command:
        close audio-14004851.mp3
    The specified device is not open or is not recognized by MCI.
Failed to close the file: audio-14004851.mp3
Traceback (most recent call last):
  File "C:/Users/Sanctuary/Desktop/VAVO/test.py", line 19, in <module>
    speak("how can I help you")
  File "C:/Users/Sanctuary/Desktop/VAVO/test.py", line 14, in speak
    playsound.playsound(audio_file) # play the audio file
  File "C:\Users\Sanctuary\AppData\Local\Programs\Python\Python310\lib\site-packages\playsound.py", line 72, in _playsoundWin
    winCommand(u'open {}'.format(sound))
  File "C:\Users\Sanctuary\AppData\Local\Programs\Python\Python310\lib\site-packages\playsound.py", line 64, in winCommand
    raise PlaysoundException(exceptionMessage)
playsound.PlaysoundException: 
    Error 263 for command:
        open audio-14004851.mp3
    The specified device is not open or is not recognized by MCI.
Abhijeet
  • 140
  • 4
  • 14

0 Answers0