Watson ASR python WebSocket
我使用使用websocket客户端库实现的python websocket,以便使用Watson ASR执行实时语音识别。这个解决方案直到最近才开始工作,但大约一个月前它停止了工作。甚至连握手都没有。奇怪的是,我没有更改代码(如下)。另一位使用不同帐户的同事也有同样的问题,因此我们不认为我们的帐户有任何问题。我已经就此联系了IBM,但由于没有握手,他们无法跟踪自己是否出了问题。websocket的代码如下所示Watson ASR python WebSocket,websocket,ibm-cloud,speech-recognition,ibm-watson,speech-to-text,Websocket,Ibm Cloud,Speech Recognition,Ibm Watson,Speech To Text,我使用使用websocket客户端库实现的python websocket,以便使用Watson ASR执行实时语音识别。这个解决方案直到最近才开始工作,但大约一个月前它停止了工作。甚至连握手都没有。奇怪的是,我没有更改代码(如下)。另一位使用不同帐户的同事也有同样的问题,因此我们不认为我们的帐户有任何问题。我已经就此联系了IBM,但由于没有握手,他们无法跟踪自己是否出了问题。websocket的代码如下所示 import websocket (...) ws = websocket.WebSo
import websocket
(...)
ws = websocket.WebSocketApp(
self.api_url,
header=headers,
on_message=self.on_message,
on_error=self.on_error,
on_close=self.on_close,
on_open=self.on_open
)
url所在的位置'wss://stream.watsonplatform.net/speech-to-text/api/v1/recognize,标头是授权令牌,以及处理回调的其他函数和方法。此时发生的情况是,此方法运行并等待连接超时。我想知道这个问题是否发生在其他运行live ASR的人身上,Watson在Python中运行这个websocket客户端库。谢谢您提供的标题信息。这就是它对我的作用 我正在使用WebSocket客户端0.54.0,这是当前的最新版本。我使用
curl -u <USERNAME>:<PASSWORD> "https://stream.watsonplatform.net/authorization/api/v1/token?url=https://stream.watsonplatform.net/speech-to-text/api"
此外,当我使用ws://
而不是wss://
时,我面临操作超时问题
更新:实时语音识别示例-@zedavid一个多月前,我们切换到使用IAM,因此
用户名和密码被替换为IAMapikey
。您应该将CloudFoundry语音到文本实例迁移到IAM。有一个页面将帮助您了解更多有关这方面的信息。您还可以创建一个新的Speech to Text实例,默认情况下该实例将是一个资源控制实例
一旦有了新实例,您将需要获得一个类似于Cloud Foundry中的令牌的access\u令牌
。访问令牌将用于授权您的请求
最后,我们最近发布了对中的语音到文本和文本到语音的支持。我鼓励您使用它,而不是为令牌交换和WebSocket连接管理编写代码
service = SpeechToTextV1(
iam_apikey='YOUR APIKEY',
url='https://stream.watsonplatform.net/speech-to-text/api')
# Example using websockets
class MyRecognizeCallback(RecognizeCallback):
def __init__(self):
RecognizeCallback.__init__(self)
def on_transcription(self, transcript):
print(transcript)
def on_connected(self):
print('Connection was successful')
def on_error(self, error):
print('Error received: {}'.format(error))
def on_inactivity_timeout(self, error):
print('Inactivity timeout: {}'.format(error))
def on_listening(self):
print('Service is listening')
def on_hypothesis(self, hypothesis):
print(hypothesis)
def on_data(self, data):
print(data)
# Example using threads in a non-blocking way
mycallback = MyRecognizeCallback()
audio_file = open(join(dirname(__file__), '../resources/speech.wav'), 'rb')
audio_source = AudioSource(audio_file)
recognize_thread = threading.Thread(
target=service.recognize_using_websocket,
args=(audio_source, "audio/l16; rate=44100", mycallback))
recognize_thread.start()
我可以知道您在头中传递什么以及如何传递吗?是的,headers={'X-Watson-Authorization-Token':self.Token}
,其中令牌是这样获得的:Authorization=AuthorizationV1(username=credentials['username'],password=credentials['password'])self.Token=Authorization.get_令牌(url=api\u base\u url)
谢谢你!您提供的代码是否允许实时语音识别?我的印象是,这是从文件中识别。这是从文件中识别,但SDK中还有其他示例,您可以看到如何使用PyAudioAs@germanatanasio听麦克风。正确地说,有一个示例可以进行实时语音识别-。我刚刚进行了验证,它可以提供临时结果。感谢这段代码和指向SDK github的链接。它正在工作!
--- request header ---
GET /speech-to-text/api/v1/recognize HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Host: stream.watsonplatform.net
Origin: http://stream.watsonplatform.net
Sec-WebSocket-Key: Yuack3TM04/MPePJzvH8bA==
Sec-WebSocket-Version: 13
X-Watson-Authorization-Token: <TOKEN>
-----------------------
--- response header ---
HTTP/1.1 101 Switching Protocols
Date: Tue, 04 Dec 2018 12:13:57 GMT
Content-Type: application/octet-stream
Connection: upgrade
Upgrade: websocket
Sec-Websocket-Accept: 4te/E4t9+T8pBtxabmxrvPZfPfI=
x-global-transaction-id: a83c91fd1d100ff0cb2a6f50a7690694
X-DP-Watson-Tran-ID: a83c91fd1d100ff0cb2a6f50a7690694
-----------------------
send: b'\x81\x87\x9fd\xd9\xae\xd7\x01\xb5\xc2\xf0D\xe9'
Connection is already closed.
### closed ###
Process finished with exit code 0
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: chat
service = SpeechToTextV1(
iam_apikey='YOUR APIKEY',
url='https://stream.watsonplatform.net/speech-to-text/api')
# Example using websockets
class MyRecognizeCallback(RecognizeCallback):
def __init__(self):
RecognizeCallback.__init__(self)
def on_transcription(self, transcript):
print(transcript)
def on_connected(self):
print('Connection was successful')
def on_error(self, error):
print('Error received: {}'.format(error))
def on_inactivity_timeout(self, error):
print('Inactivity timeout: {}'.format(error))
def on_listening(self):
print('Service is listening')
def on_hypothesis(self, hypothesis):
print(hypothesis)
def on_data(self, data):
print(data)
# Example using threads in a non-blocking way
mycallback = MyRecognizeCallback()
audio_file = open(join(dirname(__file__), '../resources/speech.wav'), 'rb')
audio_source = AudioSource(audio_file)
recognize_thread = threading.Thread(
target=service.recognize_using_websocket,
args=(audio_source, "audio/l16; rate=44100", mycallback))
recognize_thread.start()