My problem here is that I get a Runtime Error every time I run my code. Also, I am unable to bind my "Repeat" button with the "RUN" function. I do not understand why the button will not work and I am also unsure why the "self.canvas.delete()" does not work and why the new frame does not open when the puzzle has been solved (when all of the disks have been moved to a new pole) and why it opens straight away.
from Tkinter import *
import sys
import time
def Hanoi(n, src, dst, tmp, move):
if n == 0:
return n
else:
Hanoi(n-1, src, tmp, dst, move)
move(src, dst)
Hanoi(n-1, tmp, dst, src, move)
class hanoi():
master = Tk()
width = 2000
height = 400
time = 0.1
big_sep = 30
small_sep = 5
def __init__(self):
self.User_Input = input("Please enter the amount of disks")
self.canvas = Canvas(hanoi.master, height = hanoi.height, width = hanoi.width)
self.canvas.pack()
self.poles = [[], [], []]
self.Add_Objects()
def Add_Objects(self):
floor_size = 1000-2*hanoi.small_sep
self.disk_height = (400 - 4*hanoi.big_sep) / self.User_Input
self.disk_width = (floor_size - 4*hanoi.small_sep) / 3
disk_h = self.disk_height
disk_w = self.disk_width
global disk_h
global disk_w
width = hanoi.width
height = hanoi.height
small_sep = hanoi.small_sep
big_sep = hanoi.big_sep
#create poles
bar_pos = [ 4*small_sep + disk_w/2 + (disk_w+small_sep)*i for i in range(0,3) ]
for x in bar_pos:
print x
self.canvas.create_rectangle(x-small_sep, big_sep, x+small_sep, 400-big_sep-1, fill='black')
#create bases
for x in bar_pos:
print i
self.canvas.create_rectangle(x-(13*small_sep), 370, x+(13*small_sep), 410, fill = "brown")
#create disks
for i in range(self.User_Input):
print 2*small_sep + 4*small_sep*i, height-big_sep-1-disk_h*i,2*small_sep + disk_w - 4*small_sep*i, height-big_sep-1-disk_h*(i+1)
disk = self.canvas.create_rectangle(2*small_sep + 4*small_sep*i, 400-big_sep-1-disk_h*i,2*small_sep + disk_w - 4*small_sep*i, 400-big_sep-1-disk_h*(i+1),fill='blue')
self.poles[0].append(disk)
self.canvas.update()
def Move_Object(self, origin, dest):
print len(self.poles[dest]), self.User_Input-1
current_disk = self.poles[origin].pop()
self.poles[dest].append(current_disk)
x_distance = (dest - origin) * (disk_w)
y_distance = ((len(self.poles[origin]) - len(self.poles[dest])+1) * disk_h)
self.canvas.move(current_disk, x_distance, y_distance)
self.canvas.update()
time.sleep(hanoi.time)
if len(self.poles[dest]) == self.User_Input:
self.canvas.delete()
new_frame = Frame(hanoi.master, width = 300, height = 300)
new_frame.pack()
print "Yayar"
newb = Button(new_frame, text = "Replay", )
newb.place(relx = 0.5, rely = 0.5)
newb.bind("<ButtonPress-1>", self.RUN)
def RUN(self):
Hanoi(self.User_Input, 0, 2, 1, self.Move_Object)
if __name__ == "__main__":
print "hello"
hanoi().RUN()
Related
I am triying to apply Restricted Boltzman Machine (RBM) to MNIST dataset, although I am getting small reconstructing errors, when reconstruct the test set to the same dimensions as the original, the reconstructed images differ considerably from their original.
class RBM:
def init(self, n_input_neurons, n_output_neurons):
self.W = np.random.normal(loc=0.0, scale=1.0, size=(n_input_neurons, n_output_neurons)).astype(np.float32)
self.visible_bias = np.random.rand(1, n_input_neurons) #visible layer bias
self.hidden_bias = np.random.rand(1, n_output_neurons) #hidden layer bias
def __sample(self, probability_distribution):
random_dist = np.random.uniform(0, 1, probability_distribution.shape)
example = probability_distribution - random_dist
example[example > 0] = 1.0
example[example <= 0] = 0.0
return example
def __sigmoid(self, x):
return 1 / (1 + np.e ** (-x))
def __encode(self, X):
probability_distribution = self.__sigmoid(X # self.W + self.hidden_bias) #probabilities of the hidden units
return probability_distribution, self.__sample(probability_distribution)
def __decode(self, X):
probability_distribution = self.__sigmoid(X # self.W.T + self.visible_bias) #probabilities of the visible units
return probability_distribution, self.__sample(probability_distribution)
def getReconstructedOutput(self, X):
encode_probability, encode_sample = self.__encode(X)
decode_probability, decode_sample = self.__decode(encode_sample)
return decode_sample
def train(self, X, loss_function, lr=.01, epochs= 500, verbose = False):
epoch = 0
history = []
while epoch < epochs:
h0_prob, h0_state = self.__encode(X)
positive_associations = X.T.dot(h0_prob)
v1_prob, v1_state = self.__decode(h0_state)
h1_prob, h1_state = self.__encode(v1_state)
negative_associations = v1_state.T.dot(h1_prob)
#Updating weights
self.W+= lr * (positive_associations - negative_associations)
self.hidden_bias+= (lr * (h0_prob.sum(axis = 0) - h1_prob.sum(axis = 0)) )
self.visible_bias+= (lr * (X.sum(axis=0) - v1_state.sum(axis=0)) )
epoch+=1
loss = loss_function(v1_state, X) #loss
history.append(loss)
if verbose:
print(f'Epoch {epoch} ==> Loss: {loss}')
return history
What i am doing wrong?
I am using Swin transformer to build a Facial expression recognition model. The complete code is shared by Author: Rishit Dagli on 'https://keras.io/examples/vision/swin_transformers/'.
In Swin transformer class, the authors have used two Dense layers and I want to replace it with ResNet50. I came to know that the input to Resnet50 needs to be of the shape (none, none, 3). But when the images of shape (96, 96, 3) in the model are flowing through the initial layers -'PatchExtract' and 'PatchEmbedding', its getting converted to shape (576, 64). Then, when its getting passed to SwinTransformer with ResNet50, its giving an error:
Please suggest how can I embed Resnet model as a layer in SwinTransformer.
Swin Transformer class:
class SwinTransformer(layers.Layer):
def __init__(
self,
dim,
num_patch,
num_heads,
window_size=7,
shift_size=0,
num_mlp=1024,
qkv_bias=True,
dropout_rate=0.0,
**kwargs,
):
super(SwinTransformer, self).__init__(**kwargs)
self.dim = dim # number of input dimensions
self.num_patch = num_patch # number of embedded patches
self.num_heads = num_heads # number of attention heads
self.window_size = window_size # size of window
self.shift_size = shift_size # size of window shift
self.num_mlp = num_mlp # number of MLP nodes
self.norm1 = layers.LayerNormalization(epsilon=1e-5)
self.attn = WindowAttention(
dim,
window_size=(self.window_size, self.window_size),
num_heads=num_heads,
qkv_bias=qkv_bias,
dropout_rate=dropout_rate,
)
self.drop_path = DropPath(dropout_rate)
self.norm2 = layers.LayerNormalization(epsilon=1e-5)
self.mlp = keras.Sequential(
[
# I am trying to add pretrained ResNet50 here
layers.Dense(num_mlp),
layers.Activation(keras.activations.gelu),
layers.Dropout(dropout_rate),
layers.Dense(dim),
layers.Dropout(dropout_rate),
]
)
if min(self.num_patch) < self.window_size:
self.shift_size = 0
self.window_size = min(self.num_patch)
def build(self, input_shape):
if self.shift_size == 0:
self.attn_mask = None
else:
height, width = self.num_patch
h_slices = (
slice(0, -self.window_size),
slice(-self.window_size, -self.shift_size),
slice(-self.shift_size, None),
)
w_slices = (
slice(0, -self.window_size),
slice(-self.window_size, -self.shift_size),
slice(-self.shift_size, None),
)
mask_array = np.zeros((1, height, width, 1))
count = 0
for h in h_slices:
for w in w_slices:
mask_array[:, h, w, :] = count
count += 1
mask_array = tf.convert_to_tensor(mask_array)
# mask array to windows
mask_windows = window_partition(mask_array, self.window_size)
mask_windows = tf.reshape(
mask_windows, shape=[-1, self.window_size * self.window_size]
)
attn_mask = tf.expand_dims(mask_windows, axis=1) - tf.expand_dims(
mask_windows, axis=2
)
attn_mask = tf.where(attn_mask != 0, -100.0, attn_mask)
attn_mask = tf.where(attn_mask == 0, 0.0, attn_mask)
self.attn_mask = tf.Variable(initial_value=attn_mask, trainable=False)
def call(self, x):
height, width = self.num_patch
_, num_patches_before, channels = x.shape
x_skip = x
x = self.norm1(x)
x = tf.reshape(x, shape=(-1, height, width, channels))
if self.shift_size > 0:
shifted_x = tf.roll(
x, shift=[-self.shift_size, -self.shift_size], axis=[1, 2]
)
else:
shifted_x = x
x_windows = window_partition(shifted_x, self.window_size)
x_windows = tf.reshape(
x_windows, shape=(-1, self.window_size * self.window_size, channels)
)
attn_windows = self.attn(x_windows, mask=self.attn_mask)
attn_windows = tf.reshape(
attn_windows, shape=(-1, self.window_size, self.window_size, channels)
)
shifted_x = window_reverse(
attn_windows, self.window_size, height, width, channels
)
if self.shift_size > 0:
x = tf.roll(
shifted_x, shift=[self.shift_size, self.shift_size], axis=[1, 2]
)
else:
x = shifted_x
x = tf.reshape(x, shape=(-1, height * width, channels))
x = self.drop_path(x)
x = x_skip + x
x_skip = x
x = self.norm2(x)
x = self.mlp(x)
x = self.drop_path(x)
x = x_skip + x
return x
Model:
input = layers.Input(input_shape)
x = layers.RandomCrop(image_dimension, image_dimension)(input)
x = layers.RandomFlip("horizontal")(x)
x = PatchExtract(patch_size)(x)
x = PatchEmbedding(num_patch_x * num_patch_y, embed_dim)(x)
x = SwinTransformer(
dim=embed_dim,
num_patch=(num_patch_x, num_patch_y),
num_heads=num_heads,
window_size=window_size,
shift_size=0,
num_mlp=num_mlp,
qkv_bias=qkv_bias,
dropout_rate=dropout_rate,
)(x)
x = SwinTransformer(
dim=embed_dim,
num_patch=(num_patch_x, num_patch_y),
num_heads=num_heads,
window_size=window_size,
shift_size=shift_size,
num_mlp=num_mlp,
qkv_bias=qkv_bias,
dropout_rate=dropout_rate,
)(x)
x = PatchMerging((num_patch_x, num_patch_y), embed_dim=embed_dim)(x)
x = layers.GlobalAveragePooling1D()(x)
output = layers.Dense(num_classes, activation="softmax")(x)
I added ResNet50 layer but got the below error:
ValueError: Exception encountered when calling layer "swin_transformer_2" (type SwinTransformer).
in user code:
File "<ipython-input-12-4a18cac0b25c>", line 121, in call *
x = self.mlp(x)
File "/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py", line 67, in error_handler **
raise e.with_traceback(filtered_tb) from None
File "/usr/local/lib/python3.7/dist-packages/keras/engine/input_spec.py", line 214, in assert_input_compatibility
raise ValueError(f'Input {input_index} of layer "{layer_name}" '
ValueError: Exception encountered when calling layer "resnet50" (type Functional).
Input 0 of layer "conv1_pad" is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: (None, 576, 64)
Call arguments received by layer "resnet50" (type Functional):
• inputs=tf.Tensor(shape=(None, 576, 64), dtype=float32)
• training=False
• mask=None
Call arguments received by layer "swin_transformer_2" (type SwinTransformer):
• x=tf.Tensor(shape=(None, 576, 64), dtype=float32)
I am trying to simulate a ball balancing on a board with pybullet and openAI gym, but for now I am working with any shapes. I have the gym part down, but I am not sure how to approach this with pybullet. Here is an example of code I wrote up for one object, I want to make that move and balance another object on it. here is the code for the openAI env, and what I have worked on so far to render it with pybullet:
import os import gym import numpy as np import pybullet as pb import pybullet_data import math import random
class BeamEnv(gym.Env):
def __init__(self, obs_low_bounds = np.array([ 0, 0, "TBD", -45]),
obs_high_bounds = np.array([12, 12, "TBD", 45])):
self.physicsClient = pb.connect(pb.GUI) pb.setAdditionalSearchPath(pybullet_data.getDataPath()) self._seed()
"""Environment for a ball and beam system where agent has control of tilt.
Args:
obs_low_bounds (list, optional): [target location(in), ball location(in),
ball velocity(in/s), beam angle(deg)]. Defaults to [ 0, 0, "TBD", -45].
obs_high_bounds (list, optional): As above so below. Defaults to [12, 12, "TBD", 45].
"""
super(BeamEnv, self).__init__()
# Hyperparameters
self.ACC_GRAV = 386.22 # [in/s]
self.MOTOR_SPEED = 46.875 # 1.28[sec/60deg] converted to [deg/s]
self.TIME_STEP = 0.1 # [s]
# Observation Space
# _bounds = []
self.obs_low_bounds = obs_low_bounds
self.obs_high_bounds = obs_high_bounds
self._determine_max_velocity()
self.observation_space = gym.spaces.Box(low = self.obs_low_bounds,
high = self.obs_high_bounds,
dtype = np.float32)
# Action Space
# increase, decrease or keep current angle
self.action_space = gym.spaces.Descrete(3)
# Reward Range
self.reward_range = (-1, 1)
def _set_velocity_bounds(self):
"""Use Inclined Plane and Kinematics Formulas
to determine min/max velocities and set the obs_low/high_bounds
"""
# Max Distance
distance_max = self.obs_high_bounds[1]
# Max Angle
ang_max = self.obs_high_bounds[3]
# Max acceletation (Inclined Plane Formula)
a_max = self.ACC_GRAV * np.sin(np.deg2rad(ang_max))
# Max Velocity (vf^2 = v0^2 + 2ad)
vel_max = np.sqrt(2*a_max*distance_max)
# Set Bounds
self.obs_low_bounds[2] = -vel_max
self.obs_high_bounds[2] = vel_max
def _compute_observation(self): cubePos, cube0rn = pb.getBasePositionAndOrientation(self.botId) cubeEuler = pb.getEulerFromQuaternion(cubeOrn) linear, angular = pb.getBaseVelocity(self.botId) return[cubeEuler[0],angular[0],self.vt]
def _compute_reward(self): _, cubeOrn = pb.getBasePosition(self.botId) cubeEuler = pb.getEulerFromQuaternion(cube0rn) return(1 - abs(cubeEuler[0])) *
0.1 - abs(self.vt - self.vd)
def _compute_done(self): cubePos, _ = pb.getBasePositionAndOrientation(self.botId) return cubePos[2] < 0.15 or self._envStepCounter >= 1500
def reset(self, target_location = None,
ball_location = None):
pb.resetSimulation() pb.setGravity(0,0,-9.8) """default timeStep is 1/240s""" pb.setTimeStep(0.01) planeId = pb.loadURDF('plane.urdf') #loading bot cubeStarPos=[0,0,0.001] cubeStartOrientation = pb.getQuaternionFromEuler([0,0,0]) path = os.path.abspath(os.path.dirname(__file__)) self.botId = pb.loadURDF(os.path.join(path, "beam.xml"), cubeStartPos, cubeStartOrientation) self._observation = self._compute_observation() return np.array(self._observation)
"""Reset the environment so the ball is not moving, there is no angle,
Args:
target_location (float, optional): Desired location of ball. Defaults to random.
ball_location (float, optional): Current location of ball. Defaults to random.
Returns:
list: observation of (target location, ball location, ball velocity, beam angle)
"""
# Set target location
if target_location is not None:
self.target_location = target_location
else:
possible_targets = list(range(self.obs_low_bounds[0], self.obs_high_bounds[0]))
self.target_location = random.choice(possible_targets)
# Set ball location
if ball_location is not None:
self.ball_location = ball_location
else:
possible_ball_locations = list(range(self.obs_low_bounds[1], self.obs_high_bounds[1]))
self.ball_location = random.choice(possible_ball_locations)
# Set Intial Velocity and Angle to Zero
self.ball_velocity = 0 # [in/s]
self.beam_angle = 0 # [deg]
return self._next_observation()
def _next_observation(self):
"""Determines what will happen in the next time step
Returns:
list: observation of (target location, ball location, ball velocity, beam angle)
"""
# Calculate Acceleration (Inclined Plane Equation)
ball_acceleration = self.ACC_GRAV * np.sin(np.deg2rad(self.beam_angle))
# Calculate Next Position (x = x0 + v0t + 0.5at^2)
self.ball_location = self.ball_location + self.ball_velocity * self.TIME_STEP + 0.5 * ball_acceleration * self.TIME_STEP**2
# Calculate New Velocity (v = v0 + at)
self.ball_velocity = self.ball_velocity + ball_acceleration * self.TIME_STEP
# Clip Ball Location
self.ball_location = max(min(self.ball_location,
self.obs_high_bounds[1]),
self.obs_low_bounds[1])
# Clip Ball Velocity
self.ball_velocity = max(min(self.ball_velocity,
self.obs_high_bounds[2]),
self.obs_low_bounds[2])
# Return Observation
return [self.target_location, self.ball_location, self.ball_velocity, self.beam_angle]
def _take_action(self,action):
"""Determines change in angle due to action
Args:
action (int): increase, decrease or keep current angle
"""
# Change action to signs by subtracting by 1 ie (0,1,2) --> (-1,0,1)
action -= 1
# Change the angle by unit step
self.beam_angle = self.beam_angle + action * self.MOTOR_SPEED * self.TIME_STEP
# Clip
self.beam_angle = max(min(self.beam_angle,
self.obs_high_bounds[3]),
self.obs_low_bounds[3])
def step(self, action):
"""Take action, collect reward and get new observation
Args:
action (int): increase, decrease or keep current angle
Returns:
tuple: (observation, reward, done, info)
"""
# Take the action
self._take_action(action)
# Determine Success
if (round(abs((self.target_location - self.ball_location)),3) == 0) & (round(self.ball_velocity, 3) == 0) & (round(self.beam_angle, 3) == 0):
done = True
else:
done = False
# Find Reward
reward = 1 if done else -1
# Find Next Observation
obs = self._next_observation()
# Return what happened
return obs, reward, done, {}
def _seed(self, seed=None): self.np_random, seed = seeding.np_random(seed) return[seed]
here is an object in pybullet, the board I will be balancing an object on. I am not sure how to make it move by a variable force or render it based on my openAI gym script.
import numpy
import pybullet as pb
physicsClient = pb.connect(pb.GUI)
> #creates plane import pybullet_data pb.setAdditionalSearchPath(pybullet_data.getDataPath()) planeId =
> pb.loadURDF('plane.urdf')
>
>
> visualShapeId = pb.createVisualShape(
> shapeType=pb.GEOM_MESH,
> fileName='procedural_objects/126/126.obj',
> rgbaColor=None,
> meshScale=[0.1, 0.1, 0.1])
>
> collisionShapeId = pb.createCollisionShape(
> shapeType=pb.GEOM_MESH,
> fileName='procedural_objects/126/126.obj',
> meshScale=[0.1, 0.1, 0.1])
>
> #connects visual shape and collider multiBodyId = pb.createMultiBody(
> baseMass=1.0,
> baseCollisionShapeIndex=collisionShapeId,
> baseVisualShapeIndex=visualShapeId,
> basePosition=[0, 0, 1],
> baseOrientation=pb.getQuaternionFromEuler([0, 0, 0]))
>
> pb.setGravity(0, 0, -9.8) pb.setRealTimeSimulation(1)
> #use setTimeStep fn to override default time step (1/240s)
any advice how to get pybullet to generate a random shape (ignore ball) balancing on another random shape?
I'm pretty new to PyBullet and physics engines in general. My first step is trying to get one object to move towards another.
import pybullet as p
import time
import pybullet_data
DURATION = 10000
physicsClient = p.connect(p.GUI)#or p.DIRECT for non-graphical version
p.setAdditionalSearchPath(pybullet_data.getDataPath()) #optionally
print("data path: %s " % pybullet_data.getDataPath())
p.setGravity(0,0,-10)
planeId = p.loadURDF("plane.urdf")
cubeStartPos = [0,0,1]
cubeStartOrientation = p.getQuaternionFromEuler([0,0,0])
boxId = p.loadURDF("r2d2.urdf",cubeStartPos, cubeStartOrientation)
gemId = p.loadURDF("duck_vhacd.urdf", [2,2,1], p.getQuaternionFromEuler([0,0,0]) )
for i in range (DURATION):
p.stepSimulation()
time.sleep(1./240.)
gemPos, gemOrn = p.getBasePositionAndOrientation(gemId)
cubePos, cubeOrn = p.getBasePositionAndOrientation(boxId)
oid, lk, frac, pos, norm = p.rayTest(cubePos, gemPos)[0]
#rt = p.rayTest(cubePos, gemPos)
#print("rayTest: %s" % rt[0][1])
print("rayTest: Norm: ")
print(norm)
p.applyExternalForce(objectUniqueId=boxId, linkIndex=-1, forceObj=pos
,posObj=gemPos, flags=p.WORLD_FRAME)
print(cubePos,cubeOrn)
p.disconnect()
But this just gets R2 to wiggle a bit. How do I do this?
First of all, if you are moving a robot, you should do something a little more complicated, by providing some commands to the joints of the robot. Here is an example
Now assuming that you are moving something less complicated by applying an external force, the simplest thing you can do is multiply a factor alpha with the difference between the two positions; this would be your force.
For your example this would be:
import numpy as np
import pybullet as p
import time
import pybullet_data
DURATION = 10000
ALPHA = 300
physicsClient = p.connect(p.GUI) # or p.DIRECT for non-graphical version
p.setAdditionalSearchPath(pybullet_data.getDataPath()) # optionally
print("data path: %s " % pybullet_data.getDataPath())
p.setGravity(0, 0, -10)
planeId = p.loadURDF("plane.urdf")
cubeStartPos = [0, 0, 1]
cubeStartOrientation = p.getQuaternionFromEuler([0, 0, 0])
boxId = p.loadURDF("r2d2.urdf", cubeStartPos, cubeStartOrientation)
gemId = p.loadURDF("duck_vhacd.urdf", [
2, 2, 1], p.getQuaternionFromEuler([0, 0, 0]))
for i in range(DURATION):
p.stepSimulation()
time.sleep(1./240.)
gemPos, gemOrn = p.getBasePositionAndOrientation(gemId)
boxPos, boxOrn = p.getBasePositionAndOrientation(boxId)
force = ALPHA * (np.array(gemPos) - np.array(boxPos))
p.applyExternalForce(objectUniqueId=boxId, linkIndex=-1,
forceObj=force, posObj=boxPos, flags=p.WORLD_FRAME)
print('Applied force magnitude = {}'.format(force))
print('Applied force vector = {}'.format(np.linalg.norm(force)))
p.disconnect()
#Global Declarations
CHUNK_SIZE = 1024
MIN_VOLUME = 500
BUF_MAX_SIZE = 1024 * 10
RECORD_TIME_SECONDS = 7
def wakeword():
agent = snowboydecoder.HotwordDetector("res/bella.pmdl",
sensitivity=0.5)
agent.start(detected_callback=listenIntent, sleep_time=0.03)
agent.terminate()
It makes a successful detection. When it gets into listenIntent function it gives me a error
def listenIntent():
print("Hotword")
stream = pyaudio.PyAudio().open(
format = pyaudio.paInt16,
channels = 1,
rate = 44100,
input = True,
frames_per_buffer = 1024)
while True:
for i in range(0,int(44100/1024*RECORD_TIME_SECONDS)):
data = array('h',stream.read(CHUNK_SIZE))
stream_rec = pyaudio.PyAudio.open(format= pyaudio.paInt16,
channels = 2,
rate = 44100,
input = True,
frames_per_buffer = 1024)
threshold = max(stream_rec)
if threshold >= MIN_VOLUME:
print("Recording....")
frames = []
data_rec = data.read(CHUNK_SIZE)
frames.append(data_rec)
stream.stop_stream()
stream.close()
pyaudio.PyAudio.terminate()
_wavefile = wave.open("temp.wav",'wb')
_wavefile.setnchannels(1)
_wavefile.setsampwidth(pyaudio.PyAudio.get_sample_size(pyaudio.paInt16))
_wavefile.setframerate(44100)
_wavefile.writeframes(b''.join(frames))
_wavefile.close()
processAction()
def processAction():
access_token = ""
client = wit(access_token = access_token)
with open("temp.wav",'rb') as f:
response = client.speech(f, None,{'Content-Type': 'audio/wav',
'encoding':'encode',
'bits':'1024',
'rate':'44100',
'endian': 'big'})
print("Response" + str(response))
if __name__ == "__main__":
wakeword()
process
- First wakeword agent triggers
- Starts audio recording for 7 seconds
- Processes the audio file it wit.ai to understand the intent
As soon as i run the program it does a successful hotword detection but later part fails. i.e recording. I get this error.
Hotword
INFO:snowboy:Keyword 1 detected at time: 2017-10-15 10:10:53
||PaMacCore (AUHAL)|| Error on line 2490: err='-10863', msg=Audio
Unit: cannot do in current context
||PaMacCore (AUHAL)|| Error on line 2490: err='-10863', msg=Audio
Unit: cannot do in current context