Creating the audio API service

To upload the audio to our server, we are using postFile() on audioAPIService. Let's create this service now. Inside the client/app/services folder, create a file name audio.api.service.ts and update it, as shown here:

// SNIPP SNIPPimport { Injectable } from '@angular/core';import { HttpClient } from '@angular/common/http';import { Observable } from 'rxjs/Observable';@Injectable()export class AudioAPIService { constructor(private http: HttpClient) {} postFile(threadId: string, audioBlob: File): Observable < any > { const formData: FormData = new FormData(); formData.append('audio-reply', audioBlob, audioBlob.name); return this.http.post < any > (`/api/upload-audio/${threadId}`, formData); }}// SNIPP SNIPP

Get Google Cloud AI Services Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.