Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ var configCmd = &cobra.Command{
Short: "Authenticate the CLI",
Long: `This command will validate your account and store your token safely, later to be used when transcribing files.`,
Run: func(cmd *cobra.Command, args []string) {

argsArray := cmd.Flags().Args()

if len(argsArray) == 0 {
if len(args) == 0 {
fmt.Println("Please provide a token. If you don't have one, create an account at https://app.assemblyai.com")
return
} else if len(argsArray) > 1 {
} else if len(args) > 1 {
fmt.Println("Too many arguments. Please provide a single token.")
return
}
U.Token = argsArray[0]
U.Token = args[0]

checkToken := U.CheckIfTokenValid()
if !checkToken {
Expand Down
19 changes: 12 additions & 7 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@ import (
"github.com/spf13/cobra"
)

// get represents the getTranscription command
var getCmd = &cobra.Command{
Use: "get [transcription_id]",
Short: "Get a transcription",
Long: `After submitting a file for transcription, you can fetch it by passing its ID.`,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var flags S.TranscribeFlags
args = cmd.Flags().Args()
if len(args) == 0 {
printErrorProps := S.PrintErrorProps{
Error: errors.New("No transcription ID provided."),
Expand All @@ -29,8 +26,6 @@ var getCmd = &cobra.Command{
return
}
id := args[0]
flags.Poll, _ = cmd.Flags().GetBool("poll")
flags.Json, _ = cmd.Flags().GetBool("json")

U.Token = U.GetStoredToken()
if U.Token == "" {
Expand All @@ -42,12 +37,22 @@ var getCmd = &cobra.Command{
return
}

if flags.Csv != "" && !flags.Poll {
printErrorProps := S.PrintErrorProps{
Error: errors.New("CSV output is only supported with polling"),
Message: "CSV output is only supported with polling.",
}
U.PrintError(printErrorProps)
return
}

U.PollTranscription(id, flags)
},
}

func init() {
rootCmd.AddCommand(getCmd)
getCmd.Flags().BoolP("json", "j", false, "If true, the CLI will output the JSON.")
getCmd.Flags().BoolP("poll", "p", true, "The CLI will poll the transcription until it's complete.")
getCmd.PersistentFlags().BoolVarP(&flags.Poll, "poll", "p", true, "The CLI will poll the transcription until it's complete.")
getCmd.PersistentFlags().BoolVarP(&flags.Json, "json", "j", false, "If true, the CLI will output the JSON.")
getCmd.PersistentFlags().StringVar(&flags.Csv, "csv", "", "Specify the filename to save the transcript result onto a .CSV file extension")
}
255 changes: 32 additions & 223 deletions cmd/transcribe.go

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions schemas/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,22 @@ type UploadResponse struct {
}

type TranscribeFlags struct {
Poll bool `json:"poll"`
Json bool `json:"json"`
Poll bool `json:"poll"`
Json bool `json:"json"`
Csv string `json:"csv"`
}

type TranscribeParams struct {
AudioURL string `json:"audio_url"`
AutoChapters bool `json:"auto_chapters"`
AutoHighlights bool `json:"auto_highlights"`
BoostParam *string `json:"boost_param,omitempty"`
BoostParam string `json:"boost_param,omitempty"`
ContentModeration bool `json:"content_safety"`
CustomSpelling []CustomSpelling `json:"custom_spelling,omitempty"`
DualChannel bool `json:"dual_channel"`
EntityDetection bool `json:"entity_detection"`
FormatText bool `json:"format_text"`
LanguageCode *string `json:"language_code,omitempty"`
LanguageCode string `json:"language_code,omitempty"`
LanguageDetection bool `json:"language_detection"`
Punctuate bool `json:"punctuate"`
RedactPii bool `json:"redact_pii"`
Expand Down Expand Up @@ -357,3 +358,8 @@ type Release struct {
ZipballURL *string `json:"zipball_url,omitempty"`
Body *string `json:"body,omitempty"`
}

type ArrayCategories struct {
Score float64 `json:"score"`
Category string `json:"category"`
}
232 changes: 232 additions & 0 deletions utils/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
package utils

import (
"fmt"
"sort"
"strconv"
"strings"

S "github.com/AssemblyAI/assemblyai-cli/schemas"
"github.com/gosuri/uitable"
)

func textPrintFormatted(text string, words []S.SentimentAnalysisResult) {
table := uitable.New()
table.Wrap = true
table.MaxColWidth = uint(width - 10)
sentences := SplitSentences(text, true)
timestamps := GetSentenceTimestamps(sentences, words)
for index, sentence := range sentences {
if sentence != "" {
stamp := ""
if len(timestamps) > index {
stamp = timestamps[index]
}
table.AddRow(stamp, sentence)
}
}
fmt.Println(table)
fmt.Println()
}

func dualChannelPrintFormatted(utterances []S.SentimentAnalysisResult) {
table := uitable.New()
table.Wrap = true
table.MaxColWidth = uint(width - 21)
for _, utterance := range utterances {
start := TransformMsToTimestamp(*utterance.Start)
speaker := fmt.Sprintf("(Channel %s)", utterance.Channel)

sentences := SplitSentences(utterance.Text, false)
for _, sentence := range sentences {
table.AddRow(start, speaker, sentence)
start = ""
speaker = ""
}
}
fmt.Println(table)
fmt.Println()
}

func speakerLabelsPrintFormatted(utterances []S.SentimentAnalysisResult) {
table := uitable.New()
table.Wrap = true
table.MaxColWidth = uint(width - 27)

for _, utterance := range utterances {
sentences := SplitSentences(utterance.Text, false)
timestamps := GetSentenceTimestampsAndSpeaker(sentences, utterance.Words)
for index, sentence := range sentences {
if sentence != "" {
info := []string{"", ""}
if len(timestamps) > index {
info = timestamps[index]
}
table.AddRow(info[0], info[1], sentence)
}
}
}
fmt.Println(table)
fmt.Println()
}

func highlightsPrintFormatted(highlights S.AutoHighlightsResult) {
if *highlights.Status != "success" {
fmt.Println("Could not retrieve highlights")
return
}

table := uitable.New()
table.Wrap = true
table.Separator = " |\t"
table.AddRow("| count", "text")
sort.SliceStable(highlights.Results, func(i, j int) bool {
return int(*highlights.Results[i].Count) > int(*highlights.Results[j].Count)
})
for _, highlight := range highlights.Results {
table.AddRow("| "+strconv.FormatInt(*highlight.Count, 10), highlight.Text)
}
fmt.Println(table)
fmt.Println()
}

func contentSafetyPrintFormatted(labels S.ContentSafetyLabels) {
if *labels.Status != "success" {
fmt.Println("Could not retrieve content safety labels")
return
}
table := uitable.New()
table.Wrap = true
table.MaxColWidth = uint(width - 24)
table.Separator = " |\t"
table.AddRow("| label", "text")
for _, label := range labels.Results {
var labelString string
for _, innerLabel := range label.Labels {
labelString = innerLabel.Label + " " + labelString
}
table.AddRow("| "+labelString, label.Text)
}
fmt.Println(table)
fmt.Println()
}

func topicDetectionPrintFormatted(categories S.IabCategoriesResult) {
if *categories.Status != "success" {
fmt.Println("Could not retrieve topic detection")
return
}

table := uitable.New()
table.Wrap = true
table.MaxColWidth = uint(width - 20)
table.Separator = " |\t"
table.AddRow("| rank", "topic")
var ArrayCategoriesSorted []S.ArrayCategories
for category, i := range categories.Summary {
add := S.ArrayCategories{
Category: category,
Score: i,
}
ArrayCategoriesSorted = append(ArrayCategoriesSorted, add)
}
sort.SliceStable(ArrayCategoriesSorted, func(i, j int) bool {
return ArrayCategoriesSorted[i].Score > ArrayCategoriesSorted[j].Score
})

for i, category := range ArrayCategoriesSorted {
table.AddRow(fmt.Sprintf("| %o", i+1), category.Category)
}
fmt.Println(table)
fmt.Println()
}

func sentimentAnalysisPrintFormatted(sentiments []S.SentimentAnalysisResult) {
if len(sentiments) == 0 {
fmt.Println("Could not retrieve sentiment analysis")
return
}

table := uitable.New()
table.Wrap = true
table.MaxColWidth = uint(width - 20)
table.Separator = " |\t"
table.AddRow("| sentiment", "text")
for _, sentiment := range sentiments {
sentimentStatus := sentiment.Sentiment
table.AddRow("| "+sentimentStatus, sentiment.Text)
}
fmt.Println(table)
fmt.Println()
}

func chaptersPrintFormatted(chapters []S.Chapter) {
if len(chapters) == 0 {
fmt.Println("Could not retrieve chapters")
return
}

table := uitable.New()
table.Wrap = true
table.MaxColWidth = uint(width - 19)
table.Separator = " |\t"
for _, chapter := range chapters {
start := TransformMsToTimestamp(*chapter.Start)
end := TransformMsToTimestamp(*chapter.End)
table.AddRow("| timestamp", fmt.Sprintf("%s-%s", start, end))
table.AddRow("| Gist", chapter.Gist)
table.AddRow("| Headline", chapter.Headline)
table.AddRow("| Summary", chapter.Summary)
table.AddRow("", "")
}
fmt.Println(table)
fmt.Println()
}

func entityDetectionPrintFormatted(entities []S.Entity) {
if len(entities) == 0 {
fmt.Println("Could not retrieve entity detection")
return
}

table := uitable.New()
table.Wrap = true
table.MaxColWidth = uint(width - 25)
table.Separator = " |\t"
table.AddRow("| type", "text")
entityMap := make(map[string][]string)
for _, entity := range entities {
isAlreadyInMap := false
for _, text := range entityMap[entity.EntityType] {
if text == entity.Text {
isAlreadyInMap = true
break
}
}
if !isAlreadyInMap {
entityMap[entity.EntityType] = append(entityMap[entity.EntityType], entity.Text)
}
}
for entityType, entityTexts := range entityMap {
table.AddRow("| "+entityType, strings.Join(entityTexts, ", "))
}
fmt.Println(table)
fmt.Println()
}

func summaryPrintFormatted(summary *string) {
if summary == nil {
fmt.Println("Could not retrieve summary")
return
}

table := uitable.New()
table.Wrap = true
table.MaxColWidth = uint(width - 20)
table.Separator = " |\t"

table.AddRow(*summary)

fmt.Println(table)
fmt.Println()
}
Loading