MP3play module using python 3.7

  Because of their work, he made a QQ robot voice broadcast program. The main idea is to cool through QQ Q acquiring valid information extracted message.

The information on the synthesized speech Baidu AI, and local playback.

      When playing with the voice of several modules pygame, pymedia, os systems, etc., listen to how the effect is not ideal, and finally found MP3play just fine (beginning with python2.7)

  Ported to the new environment when mp3play the error. Can not play, follow the prompts to view the source code, modify the two places can be run properly.

  There are two files under the root directory mp3play __init__.py and windows.py root can mp3play view (not installed by the installation, the installation will display the installation path) through pip install

  Modify windows.py two codes

 

class _mci:
    def __init__(self):
        self.w32mci = windll.winmm.mciSendStringA
        self.w32mcierror = windll.winmm.mciGetErrorStringA

    def send(self, command):
        buffer = c_buffer(255)
        command=command.encode(encoding="utf-8")  #添加的将str 转bytes
        
        errorcode = self.w32mci(command, buffer, 254, 0)  # 默认的str(command) 不要str
        if errorcode:
            
            return errorcode, self.get_error(errorcode)
        else:
            return errorcode, buffer.value

    def get_error(self, error):
        error = int(error)
        buffer = c_buffer(255)
        self.w32mcierror(error, buffer, 254)
        return buffer.value

    def directsend(self, txt):
        (err, buf) = self.send(txt)
        if err != 0:
            print ('Error %s for "%s": %s' % (str(err), txt, buf))        # print 添加一个()
        return (err, buf)

    Changed two tests can be used. Then he looked under MP3play found mainly function call system windll.winmm.mciSendStringA

 from ctypes import windll, c_buffer

    The core call windll.winmm.mciSendStringA (b "play aa.mp3", 0, 0, 0)  

Guess you like

Origin www.cnblogs.com/XingzhiDai/p/11654484.html