Sunday, June 21, 2026
No Result
View All Result
Crypeto News
  • Home
  • Bitcoin
  • Crypto Updates
    • General
    • Blockchain
    • Ethereum
    • Altcoin
    • Mining
    • Crypto Exchanges
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Analysis
  • Regulations
  • Scam Alert
  • Videos
CRYPTO MARKETCAP
  • Home
  • Bitcoin
  • Crypto Updates
    • General
    • Blockchain
    • Ethereum
    • Altcoin
    • Mining
    • Crypto Exchanges
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Analysis
  • Regulations
  • Scam Alert
  • Videos
CRYPTO MARKETCAP
Crypeto News
No Result
View All Result

Implementing Hotword Detection with AssemblyAI’s Streaming Speech-to-Text in Go

by crypetonews
June 26, 2024
in Blockchain
Reading Time: 4 mins read
0 0
A A
0
Home Blockchain
Share on FacebookShare on Twitter







Hotword detection is a crucial feature for voice-activated systems like Siri or Alexa. In a recent tutorial by AssemblyAI, developers are guided on how to implement this functionality using AssemblyAI’s Streaming Speech-to-Text API with the Go programming language.

Introduction to Hotword Detection

Hotword detection enables an AI system to respond to specific trigger words or phrases. Popular AI systems like Alexa and Siri use predefined hotwords to activate their functionalities. This tutorial from AssemblyAI demonstrates how to create a similar system, named ‘Jarvis’ in homage to Iron Man, using Go and AssemblyAI’s API.

Setting Up the Environment

Before diving into the coding, developers need to set up their environment. This includes installing the Go bindings of PortAudio to capture raw audio data from the microphone and the AssemblyAI Go SDK for interfacing with the API. The following commands are used for setting up the project:

mkdir jarvis
cd jarvis
go mod init jarvis
go get github.com/gordonklaus/portaudio
go get github.com/AssemblyAI/assemblyai-go-sdk

Next, an AssemblyAI account is required to obtain an API key. Developers can sign up on the AssemblyAI website and configure their billing details to access the Streaming Speech-to-Text API.

Implementing the Recorder

The core functionality begins with recording raw audio data. The tutorial guides on creating a recorder.go file to define a recorder struct that captures audio data using PortAudio. This struct includes methods for starting, stopping, and reading from the audio stream.

package main

import (
“bytes”
“encoding/binary”

“github.com/gordonklaus/portaudio”
)

type recorder struct {
stream *portaudio.Stream
in []int16
}

func newRecorder(sampleRate int, framesPerBuffer int) (*recorder, error) {
in := make([]int16, framesPerBuffer)

stream, err := portaudio.OpenDefaultStream(1, 0, float64(sampleRate), framesPerBuffer, in)
if err != nil {
return nil, err
}

return &recorder{
stream: stream,
in: in,
}, nil
}

func (r *recorder) Read() ([]byte, error) {
if err := r.stream.Read(); err != nil {
return nil, err
}

buf := new(bytes.Buffer)

if err := binary.Write(buf, binary.LittleEndian, r.in); err != nil {
return nil, err
}

return buf.Bytes(), nil
}

func (r *recorder) Start() error {
return r.stream.Start()
}

func (r *recorder) Stop() error {
return r.stream.Stop()
}

func (r *recorder) Close() error {
return r.stream.Close()
}

Creating the Real-Time Transcriber

AssemblyAI’s Real-Time Transcriber requires event handlers for different stages of the transcription process. These handlers are defined in a transcriber struct and include events such as OnSessionBegins, OnSessionTerminated, and OnPartialTranscript.

package main

import (
“fmt”

“github.com/AssemblyAI/assemblyai-go-sdk”
)

var transcriber = &assemblyai.RealTimeTranscriber{
OnSessionBegins: func(event assemblyai.SessionBegins) {
fmt.Println(“session begins”)
},

OnSessionTerminated: func(event assemblyai.SessionTerminated) {
fmt.Println(“session terminated”)
},

OnPartialTranscript: func(event assemblyai.PartialTranscript) {
fmt.Printf(“%s\r”, event.Text)
},

OnFinalTranscript: func(event assemblyai.FinalTranscript) {
fmt.Println(event.Text)
},

OnError: func(err error) {
fmt.Println(err)
},
}

Stitching Everything Together

The final step involves integrating all components in the main.go file. This includes setting up the API client, initializing the recorder, and handling the transcription events. The code also includes logic for detecting the hotword and responding appropriately.

package main

import (
“context”
“fmt”
“log”
“os”
“os/signal”
“strings”
“syscall”

“github.com/AssemblyAI/assemblyai-go-sdk”
“github.com/gordonklaus/portaudio”
)

var hotword string

var transcriber = &assemblyai.RealTimeTranscriber{
OnSessionBegins: func(event assemblyai.SessionBegins) {
fmt.Println(“session begins”)
},

OnSessionTerminated: func(event assemblyai.SessionTerminated) {
fmt.Println(“session terminated”)
},

OnPartialTranscript: func(event assemblyai.PartialTranscript) {
fmt.Printf(“%s\r”, event.Text)
},

OnFinalTranscript: func(event assemblyai.FinalTranscript) {
fmt.Println(event.Text)
hotwordDetected := strings.Contains(
strings.ToLower(event.Text),
strings.ToLower(hotword),
)
if hotwordDetected {
fmt.Println(“I am here!”)
}
},

OnError: func(err error) {
fmt.Println(err)
},
}

func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)

logger := log.New(os.Stderr, “”, log.Lshortfile)

portaudio.Initialize()
defer portaudio.Terminate()

hotword = os.Args[1]

device, err := portaudio.DefaultInputDevice()
if err != nil {
logger.Fatal(err)
}

var (
apiKey = os.Getenv(“ASSEMBLYAI_API_KEY”)
sampleRate = device.DefaultSampleRate
framesPerBuffer = int(0.2 * sampleRate)
)

client := assemblyai.NewRealTimeClientWithOptions(
assemblyai.WithRealTimeAPIKey(apiKey),
assemblyai.WithRealTimeSampleRate(int(sampleRate)),
assemblyai.WithRealTimeTranscriber(transcriber),
)

ctx := context.Background()

if err := client.Connect(ctx); err != nil {
logger.Fatal(err)
}

rec, err := newRecorder(int(sampleRate), framesPerBuffer)
if err != nil {
logger.Fatal(err)
}

if err := rec.Start(); err != nil {
logger.Fatal(err)
}

for {
select {
case <-sigs:
fmt.Println(“stopping recording…”)
if err := rec.Stop(); err != nil {
log.Fatal(err)
}
if err := client.Disconnect(ctx, true); err != nil {
log.Fatal(err)
}
os.Exit(0)
default:
b, err := rec.Read()
if err != nil {
logger.Fatal(err)
}
if err := client.Send(ctx, b); err != nil {
logger.Fatal(err)
}
}
}
}

Running the Application

To run the application, developers need to set their AssemblyAI API key as an environment variable and execute the Go program with the desired hotword:

export ASSEMBLYAI_API_KEY=’***’
go run . Jarvis

This command sets ‘Jarvis’ as the hotword, and the program will respond with ‘I am here!’ whenever the hotword is detected in the audio stream.

Conclusion

This tutorial by AssemblyAI provides a comprehensive guide for developers to implement hotword detection using their Streaming Speech-to-Text API and Go. The combination of PortAudio for capturing audio and AssemblyAI for transcription offers a powerful solution for creating voice-activated applications. For more details, visit the original tutorial.

Image source: Shutterstock



Source link

Tags: AssemblyAIsdetectionHotwordImplementingSpeechtoTextStreaming
Previous Post

Bitcoin, Ether Options Worth $10B Set to Expire on Friday

Next Post

🚨 DUMP OVER ? LATEST CRYPTO NEWS & BTC UPDATES TODAY 📊

Related Posts

LINK Price Prediction: Chainlink Eyes .50 Target as Bulls Test Critical .48 Resistance
Blockchain

LINK Price Prediction: Chainlink Eyes $28.50 Target as Bulls Test Critical $26.48 Resistance

August 23, 2025
AVAX Price Prediction: Targeting  Breakout After 13% Rally Sets Stage for August Surge
Blockchain

AVAX Price Prediction: Targeting $32 Breakout After 13% Rally Sets Stage for August Surge

August 23, 2025
Townstar Introduces Gems to Tackle Spoiled Soil Challenge
Blockchain

Townstar Introduces Gems to Tackle Spoiled Soil Challenge

August 22, 2025
Interpol Busts 1,200 Cybercriminals in Global Crypto Raid
Blockchain

Interpol Busts 1,200 Cybercriminals in Global Crypto Raid

August 22, 2025
BTC Holder Loses M After Falling for Fake Support Trap
Blockchain

BTC Holder Loses $91M After Falling for Fake Support Trap

August 22, 2025
Bitcoin (BTC) 2025 Market Projections Released by Bitwise
Blockchain

Bitcoin (BTC) 2025 Market Projections Released by Bitwise

August 22, 2025
Next Post
🚨 DUMP OVER ? LATEST CRYPTO NEWS & BTC UPDATES TODAY 📊

🚨 DUMP OVER ? LATEST CRYPTO NEWS & BTC UPDATES TODAY 📊

XRP Price To Plunge Hard, As Ripple Supply On Exchange Drop Sharply 

XRP Price To Plunge Hard, As Ripple Supply On Exchange Drop Sharply 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

RECOMMENDED

No Content Available

  • USD
  • EUR
  • GBP
  • AUD
  • JPY
  • bitcoinBitcoin(BTC)
    $64,200.001.41%
  • ethereumEthereum(ETH)
    $1,733.591.66%
  • tetherTether(USDT)
    $1.00-0.01%
  • binancecoinBNB(BNB)
    $589.201.62%
  • usd-coinUSDC(USDC)
    $1.000.00%
  • rippleXRP(XRP)
    $1.150.71%
  • solanaSolana(SOL)
    $73.345.26%
  • tronTRON(TRX)
    $0.3264321.24%
  • Figure HelocFigure Heloc(FIGR_HELOC)
    $1.030.00%
  • HyperliquidHyperliquid(HYPE)
    $69.821.81%
  • Trending
  • Comments
  • Latest
4 Expert Tips to Turn Blank Pages Into Business Blueprints

4 Expert Tips to Turn Blank Pages Into Business Blueprints

October 21, 2024
Top Crypto Portfolio Rebalancing Tools (Automated & Manual)

Top Crypto Portfolio Rebalancing Tools (Automated & Manual)

April 13, 2025
What are Meta Transactions? Exploring ERC-2771

What are Meta Transactions? Exploring ERC-2771

October 25, 2023
How to Set Up NFT Sales Notifications

How to Set Up NFT Sales Notifications

October 19, 2023
Uniswap v4 Teases Major Updates for 2025

Uniswap v4 Teases Major Updates for 2025

January 2, 2025
How to Bridge Avalanche (AVAX) to Fantom (FTM)?

How to Bridge Avalanche (AVAX) to Fantom (FTM)?

November 11, 2022
AI Expert: Truth Protocols Could Become the SSL of the Information Age

AI Expert: Truth Protocols Could Become the SSL of the Information Age

August 24, 2025
Analyst Says Dogecoin Price Is Entering Expansion Phase, Here’s What It Means

Analyst Says Dogecoin Price Is Entering Expansion Phase, Here’s What It Means

August 24, 2025
Robert Kiyosaki Exposes Brutal Truth Behind Sudden Wealth and Collapse

Robert Kiyosaki Exposes Brutal Truth Behind Sudden Wealth and Collapse

August 24, 2025
Ethereum’s Tech Edge Could Outshine Bitcoin — Here’s How

Ethereum’s Tech Edge Could Outshine Bitcoin — Here’s How

August 23, 2025
IRS Loses Top Crypto Enforcer After Only 90 Days on the Job

IRS Loses Top Crypto Enforcer After Only 90 Days on the Job

August 23, 2025
US Court Grants Stay In Coinbase Biometric Data Lawsuit — Details

US Court Grants Stay In Coinbase Biometric Data Lawsuit — Details

August 23, 2025
Crypeto News

Find the latest Bitcoin, Ethereum, blockchain, crypto, Business, Fintech News, interviews, and price analysis at Crypeto News.

CATEGORIES

  • Altcoin
  • Analysis
  • Bitcoin
  • Blockchain
  • Crypto Exchanges
  • Crypto Updates
  • DeFi
  • Ethereum
  • Metaverse
  • Mining
  • NFT
  • Regulations
  • Scam Alert
  • Uncategorized
  • Videos
  • Web3

LATEST UPDATES

  • AI Expert: Truth Protocols Could Become the SSL of the Information Age
  • Analyst Says Dogecoin Price Is Entering Expansion Phase, Here’s What It Means
  • Robert Kiyosaki Exposes Brutal Truth Behind Sudden Wealth and Collapse
  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us
  • About Us

Copyright © 2022 Crypeto News.
Crypeto News is not responsible for the content of external sites.

No Result
View All Result
  • Home
  • Bitcoin
  • Crypto Updates
    • General
    • Blockchain
    • Ethereum
    • Altcoin
    • Mining
    • Crypto Exchanges
  • NFT
  • DeFi
  • Web3
  • Metaverse
  • Analysis
  • Regulations
  • Scam Alert
  • Videos

Copyright © 2022 Crypeto News.
Crypeto News is not responsible for the content of external sites.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In