-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Voice entry demo #31010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Voice entry demo #31010
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
5d69fce
Basic openwakeword demo
jakethesnake420 74d09de
removed pyaudio and update README
jakethesnake420 c9cdba2
microphone subscriber stream
jakethesnake420 e6dc6f7
bump cereal
jakethesnake420 248fe17
cleanup
jakethesnake420 b4980a6
switch to new microphone service
jakethesnake420 7a95204
bump cereal
jakethesnake420 f619eb7
micd: Send microphoneRaw and don't enforce rate with rate keeper
jakethesnake420 4677b04
bump cereal
jakethesnake420 105aedb
use 16bit audio
jakethesnake420 7854f96
Track skipped samples
jakethesnake420 6bcc4cc
run until closed
jakethesnake420 87a2891
run until closed
jakethesnake420 5d1c47d
bump cereal
jakethesnake420 a3c28fc
Wait for sounddevice to start before rate keeper starts
jakethesnake420 415d27c
Buffer samples in queue for slow connections and publish responses to…
jakethesnake420 6338af3
fix typo
jakethesnake420 fa04d3d
better timeouts for google speech api
jakethesnake420 70605c5
update poetry
jakethesnake420 0ab436c
update speech_printer.py
jakethesnake420 95373f9
speechToText UI label widget
jakethesnake420 f2c07dc
micd don't use ratekeeper
jakethesnake420 606fff2
remove whitespace
jakethesnake420 23e500b
delete my_micd
jakethesnake420 fa3aa0b
delete stand_alones
jakethesnake420 c07ce00
poetry set google clound speech version
jakethesnake420 acdb3af
use rev.ai instead of google
jakethesnake420 43e763d
update ui assistant logig
jakethesnake420 5174581
bump cereal
jakethesnake420 f739b11
fix imports
jakethesnake420 18dcfed
assert Model __init__.py
jakethesnake420 d0b875a
speech_printer.py update
jakethesnake420 f0d7c6f
fix messaging init
jakethesnake420 4884cf8
update README.md
jakethesnake420 f48cfbe
Delete google speech spyware
jakethesnake420 edfa000
replace google speech with rev.ai in .toml
jakethesnake420 c8aeda3
init final transcript
jakethesnake420 c90fc4f
added wakewordd unit test without sound files
jakethesnake420 11ad162
fix tab size
jakethesnake420 6f2e24c
oops
jakethesnake420 523080f
more modular
jakethesnake420 0d36434
keep the assistantOverlay raised
jakethesnake420 60cb674
**hopefully** make the assistant overlay less buggy
jakethesnake420 b7dcf8d
Added wakeword unittest
jakethesnake420 9d5e429
bump cereal
jakethesnake420 33bde7d
oops
jakethesnake420 60d7e69
do it like this
jakethesnake420 2841aff
I think this is good enough
jakethesnake420 0a60f5f
set .gitmodules
jnewb1 7be0f17
Merge remote-tracking branch 'origin/master' into wake-word-demo
jnewb1 04c571c
bump
jnewb1 fa7c4bc
bump
jnewb1 b651db3
Only run onroad
jakethesnake420 2d2dc83
Only run onroad unless PC
jakethesnake420 7dfe752
widget state refactor. Hopefully less buggy
jakethesnake420 207123b
bump cereal
jakethesnake420 b9f64a5
don't print so much
jakethesnake420 e809f8e
cleanup
jakethesnake420 52a3daa
cleanup added nav setter
jakethesnake420 6d2d7f2
nav setter and cleanup
jakethesnake420 9c045db
less lines. remove comments
jakethesnake420 1d12867
less lines
jakethesnake420 a967a15
cleaning
jakethesnake420 abbafb6
fix static analysis
jakethesnake420 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule cereal
updated
from 20b65e to 02e154
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #include "selfdrive/ui/qt/widgets/assistant.h" | ||
|
|
||
| AssistantOverlay::AssistantOverlay(QWidget *parent) : QLabel(parent) { | ||
|
|
||
| setStyleSheet("QLabel {" | ||
| " background-color: #373737;" | ||
| " border-radius: 20px;" | ||
| " font-family: 'Inter';" | ||
| " font-size: 60px;" | ||
| " color: white;" // Text color | ||
| "}"); | ||
|
|
||
| // Set up the animations | ||
| showAnimation = new QPropertyAnimation(this, "geometry"); | ||
| showAnimation->setDuration(250); // Duration in milliseconds | ||
| hideAnimation = new QPropertyAnimation(this, "geometry"); | ||
| hideAnimation->setDuration(250); | ||
| int height = 100; // Fixed height | ||
| setGeometry(0, 0, 0, height); | ||
| hide(); | ||
|
|
||
| hideTimer = new QTimer(this); | ||
| connect(hideTimer, &QTimer::timeout, this, [this]() { animateOverlay(false); }); | ||
| QObject::connect(uiState(), &UIState::uiUpdate, this, &AssistantOverlay::updateState); | ||
| } | ||
|
|
||
| void AssistantOverlay::animateOverlay(bool show) { | ||
| int parentCenterX = parentWidget()->width() / 2; | ||
| finalWidth = parentWidget()->width() * 0.5; | ||
| int startX = parentCenterX - finalWidth / 2; | ||
| QRect centerRect(parentCenterX, 0, 0, height()); // Centered, zero width | ||
| QRect fullRect(startX, 0, finalWidth, height()); // Adjusted x, final width | ||
|
|
||
| if (show) { | ||
| showAnimation->setStartValue(centerRect); | ||
| showAnimation->setEndValue(fullRect); | ||
| this->show(); | ||
| showAnimation->start(); | ||
| } else { | ||
| hideAnimation->setStartValue(fullRect); | ||
| hideAnimation->setEndValue(centerRect); | ||
| hideAnimation->start(); | ||
| hideTimer->stop(); | ||
| } | ||
| } | ||
|
|
||
| void AssistantOverlay::updateText(QString text) { | ||
| this->setText(text); | ||
| this->setAlignment(QFontMetrics(this->font()).horizontalAdvance(text) > this->finalWidth ? Qt::AlignRight : Qt::AlignCenter); | ||
| } | ||
|
|
||
| void AssistantOverlay::updateState(const UIState &s) { | ||
| const SubMaster &sm = *(s.sm); | ||
| if (!sm.updated("speechToText")) return; | ||
|
|
||
| static cereal::SpeechToText::State current_state = cereal::SpeechToText::State::NONE; | ||
| cereal::SpeechToText::State request_state = sm["speechToText"].getSpeechToText().getState(); | ||
| // Check for valid state transition | ||
| if (current_state == cereal::SpeechToText::State::BEGIN || | ||
| (current_state == cereal::SpeechToText::State::NONE && | ||
| (request_state == cereal::SpeechToText::State::EMPTY || | ||
| request_state == cereal::SpeechToText::State::FINAL || | ||
| request_state == cereal::SpeechToText::State::NONE)) || | ||
| request_state == cereal::SpeechToText::State::BEGIN) { | ||
|
|
||
| current_state = request_state; // Update state | ||
| switch (current_state) { // Handle UI updates | ||
| case cereal::SpeechToText::State::BEGIN: | ||
| if (!hideTimer->isActive()) animateOverlay(true); | ||
| updateText("Hello, I'm listening"); | ||
| hideTimer->start(30000); | ||
| break; | ||
| case cereal::SpeechToText::State::EMPTY: | ||
| updateText("Sorry, I didn't catch that"); | ||
| hideTimer->start(8000); | ||
| break; | ||
| case cereal::SpeechToText::State::ERROR: | ||
| updateText("Sorry, an error occorred"); | ||
| hideTimer->start(8000); | ||
| break; | ||
| case cereal::SpeechToText::State::FINAL: | ||
| case cereal::SpeechToText::State::NONE: | ||
| updateText(QString::fromStdString(sm["speechToText"].getSpeechToText().getTranscript())); | ||
| hideTimer->start(request_state == cereal::SpeechToText::State::FINAL ? 8000 : 30000); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #pragma once | ||
|
|
||
| #include "selfdrive/ui/ui.h" | ||
| #include <QLabel> | ||
| #include <QPropertyAnimation> | ||
|
|
||
| class AssistantOverlay : public QLabel { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| explicit AssistantOverlay(QWidget *parent = nullptr); | ||
| void animateOverlay(bool show); | ||
|
|
||
| private: | ||
| void updateText(const QString text); | ||
| void startHideTimer(); | ||
| QTimer *hideTimer; | ||
| QPropertyAnimation *showAnimation; | ||
| QPropertyAnimation *hideAnimation; | ||
| int finalWidth; | ||
|
|
||
| private slots: | ||
| void updateState(const UIState &s); | ||
|
|
||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,12 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { | |
| main_layout = new QStackedLayout(this); | ||
| main_layout->setMargin(0); | ||
|
|
||
| assistantOverlay = new AssistantOverlay(this); | ||
| homeWindow = new HomeWindow(this); | ||
| main_layout->addWidget(homeWindow); | ||
| QObject::connect(homeWindow, &HomeWindow::openSettings, this, &MainWindow::openSettings); | ||
| QObject::connect(homeWindow, &HomeWindow::closeSettings, this, &MainWindow::closeSettings); | ||
| QObject::connect(homeWindow, &HomeWindow::requestRaiseAssistantOverlay, this, &MainWindow::raiseAssistantOverlay); | ||
|
|
||
| settingsWindow = new SettingsWindow(this); | ||
| main_layout->addWidget(settingsWindow); | ||
|
|
@@ -37,11 +39,13 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { | |
| if (!offroad) { | ||
| closeSettings(); | ||
| } | ||
| assistantOverlay->raise(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure all these raises are required |
||
| }); | ||
| QObject::connect(device(), &Device::interactiveTimeout, [=]() { | ||
| if (main_layout->currentWidget() == settingsWindow) { | ||
| closeSettings(); | ||
| } | ||
| assistantOverlay->raise(); | ||
| }); | ||
|
|
||
| // load fonts | ||
|
|
@@ -68,6 +72,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { | |
| void MainWindow::openSettings(int index, const QString ¶m) { | ||
| main_layout->setCurrentWidget(settingsWindow); | ||
| settingsWindow->setCurrentPanel(index, param); | ||
| assistantOverlay->raise(); | ||
| } | ||
|
|
||
| void MainWindow::closeSettings() { | ||
|
|
@@ -80,6 +85,7 @@ void MainWindow::closeSettings() { | |
| homeWindow->showMapPanel(true); | ||
| } | ||
| } | ||
| assistantOverlay->raise(); | ||
| } | ||
|
|
||
| bool MainWindow::eventFilter(QObject *obj, QEvent *event) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| from cereal import messaging, log | ||
| from openpilot.common.params import Params | ||
| import json | ||
|
|
||
| STTState = log.SpeechToText.State | ||
|
|
||
| sm = messaging.SubMaster(["speechToText"]) | ||
| import os | ||
| import re | ||
| import requests | ||
| import urllib.parse | ||
|
|
||
| def get_coordinates_from_transcript(transcript, proximity, mapbox_access_token): | ||
| # Regular expression to find 'navigate to' or 'directions to' followed by an address | ||
| pattern = r'\b(navigate to|directions to)\b\s+(.*?)(\.|$)' | ||
| # Search for the pattern in the transcript | ||
| match = re.search(pattern, transcript, re.IGNORECASE) | ||
| if match: | ||
| address = match.group(2).strip() | ||
| encoded_address = urllib.parse.quote(address) | ||
| mapbox_url = f"https://api.mapbox.com/geocoding/v5/mapbox.places/{encoded_address}.json?access_token=pk.eyJ1IjoicnlsZXltY2MiLCJhIjoiY2xjeDl5aGp4MTBmeDNzb2Vua2QyNWN1bSJ9.CrbD-j1LQkBdOqyWcZneyQ" | ||
| response = requests.get(mapbox_url) | ||
| if response.status_code == 200: | ||
| data = response.json() | ||
| # Assuming the first result is the most relevant | ||
| if data['features']: | ||
| coordinates = { | ||
| "latitude": data['features'][0]['geometry']['coordinates'][0], | ||
| "longitude": data['features'][0]['geometry']['coordinates'][1], | ||
| } | ||
| return coordinates | ||
| print("No coordinates") | ||
| print(f"Mapbox API error: {response.status_code}") | ||
| return False | ||
|
|
||
| def main(): | ||
| params = Params() | ||
| mapbox_access_token = os.environ["MAPBOX_TOKEN"] | ||
| while True: | ||
| dest = False | ||
| transcript: str = "" | ||
| sm.update(0) | ||
| if sm.updated["speechToText"]: | ||
| transcript = sm["speechToText"].transcript | ||
| if not sm["speechToText"].state == log.SpeechToText.State.final: | ||
| print(f'Interim result: {transcript}') | ||
| else: | ||
| print(f'Final result: {transcript}') | ||
| proximity = params.get("LastGPSPosition") | ||
| print(proximity) | ||
| dest = get_coordinates_from_transcript(transcript,proximity, mapbox_access_token) | ||
| if dest: | ||
| params.put("NavDestination", json.dumps(dest)) | ||
| print(dest) | ||
| dest = False | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.