0

I have write program for Voice recognition Module V3.1 and Raspberrypi 3b+ , but my problem is I am not able to write any of my voice command on voice module when I speech my command its not return anything so its not able to write on module.I have connected the V 3.1 module to raspberry pi 3 b+ using TTL module I also try with mini-com or serial0 but i got same result

Here is the program Details:

#!/usr/bin/env python
import time
import serial



counter=0

def Off():
  print('Yes I got one as a string')


def Go():
    print('yes i got two as a string')

if __name__ == '__main__':

    commands = {'1':Go, '2':Off}

    ser = serial.Serial(
    port='/dev/ttyS0', 
    baudrate = 9600,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    bytesize=serial.EIGHTBITS,
    timeout=1
                        )
    ser.flushInput()

    ser.write(serial.to_bytes([0xAA,0x08,0x15,0x1F,0x00,0x01,
                        0x02,0x03,0x04,0x0A]))   #auto load the voice    
    time.sleep(0.5)

   for i in range(2):


      ser.write(serial.to_bytes([0xAA,0x08,0x30,0x00,0x01,
          0x02,0x03,0x04,0x05,0x0A])) # set speech module to waiting state to recognize the voice records
         time.sleep(0.5)
      ser.write(serial.to_bytes([0xAA,0x04,0x32,0x02,0x00,0x0A])) #import system group 1 and await voice input


    try:

       while True:       
            x=ser.readline(1024)
            time.sleep(2)
            print(x)
            myString = str(x.decode("utf-8","ignore"))
            print('mystring is: ')
            print(myString)
            int_val = int.from_bytes(x, byteorder='big') # convert to integer
            print(int_val)
            #myData = x.decode("ASCII")
            #print(myData)
            #m1 = float(myData)
            #print(m1)
            if myString=='1':
                commands[myString]()
                #commands[myData]()
            else:
                continue

    finally:

 # this code is working only for string formate   
      print("its Okay")

Output:

b'\xaa\x0f0\x00\x00\xfd\x01\xfd\x02\xfd\x03\xfd\x04\xfd\x05\xfd\n'
mystring is: 
0����

57868190026823824309817875098227198786826
b'\xaa\r2\x00\x00\x01\x02\x03\x04\x05\x06\x07\x7f\x00\n'
mystring is: 

2������

882958098683898641259850589970300938
b''
0
b''
mystring is: 

0
b''
mystring is: 

0
b''
mystring is: 

0
b''

When I said one or two I didn't get any reply

I am looking for solution..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.