Select to view content in your preferred language

Speech Recognition and Arcpy

3521
4
07-22-2015 02:56 PM
WinnKetchum
Deactivated User

Hello All,

I've been doing some python development/scripting, trying to figure out how to complete Arcpy processes with speech recognition.  At the moment I'm using pyspeech, which utilizes windows speech recognition, and as a test I'm having it do something simply like copy a set of point features.  The script works as a stand-alone python script, however when I try to incorporate it into the pyspeech method, I get the an error that the file I'm trying to copy is not supported or doesn't exist.  Which to me is wrong, as it works otherwise.  Below are copies of the script, both with and without pyspeech, as well as the error I get when using it with pyspeech.

Thank you in advance for any help with this issue.

Winn

################################

Code without pyspeech:

import os
import arcpy
from arcpy import env
from datetime import datetime

now = datetime.now()
Ver_Date = str(now.strftime("%m/%d/%Y"))
File_Date = str(now.strftime("%m%d%y"))

workspace = r"C:\Users\ketchum\Documents\Python Projects\Field Work Master\FieldWork.gdb"
gps_fc = workspace + "\\GPSLog_" + File_Date
note_fc = workspace + "\\Notes_" + File_Date
note_fc2 = workspace + "\\Notes_" + File_Date + "_Copy"

arcpy.AddMessage('Copying notes.')
arcpy.Copy_management(note_fc, note_fc2)

############################

Code with pyspeech:

import speech
import arcpy
from datetime import datetime
import time

now = datetime.now()
Ver_Date = str(now.strftime("%m/%d/%Y"))
File_Date = str(now.strftime("%m%d%y"))

workspace = r"C:\Users\ketchum\Documents\Python Projects\Field Work Master\FieldWork.gdb"

gps_fc = workspace + "\\GPSLog_" + File_Date
note_fc = workspace + "\\Notes_" + File_Date
note_fc2 = workspace + "\\Notes_" + File_Date + "_Copy"

speech.say('Ready for your instruction.')

print File_Date

def L1Callback(phrase, listener):
    speech.say(phrase)
    if phrase == "notes":
        arcpy.AddMessage('Copying notes.')
        arcpy.Copy_management(note_fc, note_fc2)
        speech.say('Notes have been copied.')
    if phrase == "goodbye":
        listener.stoplistening()
   

L1 = speech.listenforanything(L1Callback)

while L1.islistening(): 
    time.sleep(1)

#######################################################   

Error when using AddNote_pyspeech.py:

072215

Copying notes.

pythoncom error: Python error invoking COM method.

Traceback (most recent call last):

  File "C:\Python26\ArcGIS10.0\lib\site-packages\win32com\server\policy.py", line 277, in _Invoke_

    return self._invoke_(dispid, lcid, wFlags, args)

  File "C:\Python26\ArcGIS10.0\lib\site-packages\win32com\server\policy.py", line 282, in _invoke_

    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)

  File "C:\Python26\ArcGIS10.0\lib\site-packages\win32com\server\policy.py", line 585, in _invokeex_

    return func(*args)

  File "C:\Python26\ArcGIS10.0\lib\site-packages\speech.py", line 135, in OnRecognition

    self._callback(phrase, self._listener)

  File "C:\Users\ketchum\Documents\Python Projects\Voice Recognition\AddNote_pyspeech.py", line 35, in L1Callback

    arcpy.Copy_management(note_fc, note_fc2)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 3010, in Copy

    raise e

ExecuteError: Failed to execute. Parameters are not valid.

ERROR 000732: Input Data Element: Dataset C:\Users\ketchum\Documents\Python Proj

ects\Field Work Master\FieldWork.gdb\Notes_072215 does not exist or is not supported

Failed to execute (Copy).

0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

a question... how is the raw syntax and spaces handled by the language program ??  (ie r"c:\yourpath\yourfile.yourextension"

0 Kudos
WinnKetchum
Deactivated User

Yes, I think the issue was that there were spaces in the pathname.  I've utilized r"pathname" before to account for this, however, it doesn't seem to work with pyspeech.  I just tried it with a pathname without spaces and it works.  Thank you for your help.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Can you use, and do you get the same error with CopyFeatures_management rather than Copy_management?

0 Kudos
WinnKetchum
Deactivated User

I get the same error with CopyFeatures as I do with Copy.  It seems it was the pathname itself that was causing the issue.  Thank you for your suggestion though.

0 Kudos